Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by ltrout1999 · Apr 13, 2016 at 01:53 AM · decimalpricing

Changing prices after a certain point?

I'm prototyping a game similar to adventure capitalist and I've ran into a slight problem. Whenever my prices surpass 10,000,000, unity changes the price to 1.xxxxx e + 0x, instead of saying 10,234,502 for example. I want to setup something to say when the price passes 1,000,000 to change it to x.xxx million and then at 1,000,000,000, it will change to x.xxx billion, and so on. How would I go about setting this up? And I don't want to show decimals under 1,000,000.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ltrout1999 · Apr 13, 2016 at 02:31 AM 0
Share

@dhore , @ZefanS

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Rotavele · Apr 13, 2016 at 05:47 AM

I have written a game similar to this, and I leave the cash alone so unity and the data goes smoothly.

Instead I use the game script (in update frame) to send the cash value to my currency converter script which displays the data such as "XX.xx Billion".

Basically you just need an if/else statement to check the amount and if it's over X,XXX,XXX,XXX then divide by 1,000,000 and alter the UI to display "XXX.xx Billions".

Also remember to start with the largest amount you wish to code in (Ex: Decillion) and if it's smaller, then use an else statement to check the next amount and just keep going down the line.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Redwolve · Apr 13, 2016 at 03:27 AM

@ltrout1999

my first thoughts on this would be to check for it to be >= to 1,234,567 then multiply by 1X10^(-3*counter) this counter will be how many time you have performed this already +1 so first time it will be 1 so it will multiply by .001 and the second .000001, etc.. This will give you 1,234.567 first time. Then Mathf.Round, or Floor, or Ceil which every you want to use. this will give you 1,234. Then multiply by .001 once more and you will get 1.234. keep a count of how many times this condition is met and create a case switch to add either + "million" or +"billion", etc.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ltrout1999 · Apr 13, 2016 at 03:33 AM 0
Share

I did have it setup like this:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class IncreasePrice : $$anonymous$$onoBehaviour 
 {
     public float Price = 100;
     public float increase$$anonymous$$ultiplier = 1.25f;
     public Text priceText;
 
     public float currentPrice;
     int clicks;
     Button priceButton;
 
     void Start()
     {
         currentPrice = Price;
         clicks = 0;
 
         priceButton = gameObject.GetComponent<Button> ();
     }
 
     void Update()
     {
         currentPrice = currentPrice;
         //priceText.text = "Price: " + currentPrice + "\n" + "Clicks: " + clicks;
 
         if (currentPrice > 1000000) 
         {
             currentPrice = currentPrice / 1000000;
             priceText.text = "Price: " + currentPrice + "million";
         } 
         else if (currentPrice < 1000000) 
         {
             currentPrice = (int)currentPrice;
             priceText.text = "Price: " + currentPrice;
         }
     }
 
     public void OnClick()
     {
         currentPrice = currentPrice * increase$$anonymous$$ultiplier;
         clicks += 1;
     }
 }
 

but it seemed to get to 10,000,000 and then just stay at one and wouldn't update the price with the multiplier.

avatar image Redwolve ltrout1999 · Apr 13, 2016 at 03:45 AM 0
Share

i dont believe it would be causing your problem, however your dont have a condition for = to 1,000,000. i cant see anything wrong other than that. And what is the purpose of currentPrice = currentPrice; in your update? I'll keep looking for a problem though.

avatar image ltrout1999 Redwolve · Apr 13, 2016 at 03:47 AM 0
Share

It might not be needed but after the OnClick function, I was making sure the price kept updated. Yeah it's probably not needed since the OnClick will update it automatically so

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

56 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why the decimals change when I move away from the object? 0 Answers

Float without comma 1 Answer

Calculate exact time passed after two decimal point (ex: 0.2143) 0 Answers

Dont round decimal places? 2 Answers

How to get type double to vector3? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges