Dont round decimal places?
Is there a way to not round my decimal places when i display them as a label? EX: I have a number 2.009289 and it keeps rounding to 2.01 whenever i show it in a label and i don't want to display that much because the player doesn't have that much money. The number im using is a double(needed for making this clicker game as i need bigger numbers than 2.1 billion) Im using ToString
MyNumber.ToString("#,##0.00");
I hope this can be done.
Answer by cjdev · Sep 27, 2015 at 06:44 AM
Try using a different formatting parameter:
MyNumber.ToString("N6");
That will show 6 decimal places and commas. Note that it will always show 6 places, including trailing zeros, so if you don't want that you'll have to check for it and adjust the number accordingly.
Its still rounding up. I have this much: 10.0694993176423 and its telling me i have this much: 10.07 and i need it to show 10.06. the variable its self in the inspector says the exact amount but when its displayed via a label its rounding it.
Answer by Escaran · Sep 27, 2015 at 07:32 PM
If I've understood what you're attempting correctly, you could do this:
double d = 10.069;
double rounded = (double)((int)(d * 100)) / 100;
Debug.Log(d.ToString());
Debug.Log(rounded.ToString());
This will first print 10.069 (the original number), then 10.06 (rounded down to 2 decimal places). Changing the '100' determines to what decimal place it will rounded. Casting to an int is what performs the actual rounding down. Casting that back to a double and then dividing again gives you your original number rounded to a certain number of decimals.
What would that be in JS? I tried this and it still rounded. (($$anonymous$$yNumber * 100) / 100).ToString("#,##0.00");