Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Polraudio · Sep 27, 2015 at 02:29 AM · guilabeldecimaltostringrounding

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.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 1 · 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 Polraudio · Sep 27, 2015 at 05:21 PM 0
Share

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.

avatar image
0

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.

Comment
Add comment · Show 1 · 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 Polraudio · Sep 27, 2015 at 08:13 PM 0
Share

What would that be in JS? I tried this and it still rounded. (($$anonymous$$yNumber * 100) / 100).ToString("#,##0.00");

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

34 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

Related Questions

OnGUI() problems in unity 5.6, worked with Unity 4. 0 Answers

Find a string in an array from another script 2 Answers

GUI Scripting Hierarchy 0 Answers

How to display extra 0 at the end of decimal 2 Answers

GUI Labels doesn't center anymore 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