Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
1
Question by RdJ · May 22, 2010 at 12:34 PM · numberprecisiondecimal

High precision numbers

I have numbers that need precision of at least 10 decimals, while they are as big as 10^8.

Is this possible??

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
6

Answer by duck · May 22, 2010 at 01:02 PM

Yes this is possible.

Because Unity runs Mono, you have access to all the standard .net base types. There are a number of different base types of varying precision which you can use to hold numeric values:

Name Type Signed Bytes Values

sbyte System.Sbyte Yes 1 -128 to 127 short System.Int16 Yes 2 -32768 to 32767 int System.Int32 Yes 4 -2147483648 to 2147483647 long System.Int64 Yes 8 -9223372036854775808 to 9223372036854775807 byte System.Byte No 1 0 to 255 ushort System.Uint16 No 2 0 to 65535 uint System.UInt32 No 4 0 to 4294967295 ulong System.Uint64 No 8 0 to 18446744073709551615

float System.Single Yes 4 Approximately 1.5 x 10-45 to 3.4 x 1038 with 7 significant figures

double System.Double Yes 8 Approximately 5.0 x 10-324 to 1.7 x 10308 with 15 or 16 significant figures

decimal System.Decimal Yes 12 Approximately 1.0 x 10-28 to 7.9 x 1028 with 28 or 29 significant figures

In your case, it sounds like you'd want to use either double or decimal.

double has a lower precision, but a wider range of potential exponents, and - like float - is not "decimally accurate" becuase it stores values as a binary floating point type.

decimal has much higher precision, and is "decimally accurate" because it stores values as a decimal floating point type. For this reason, it's generally used for "naturally exact decimal values", such as financial calculations.

Comment
Add comment · Show 2 · 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 RdJ · May 22, 2010 at 06:17 PM 0
Share

I can't really test it, because System.Decimal vars don't show up in Inspector panel... :( How can I view them??

avatar image ina · Feb 24, 2012 at 11:55 AM 0
Share

@Duck have you actually tried these data types? Even using System.Decimal it seems Unity implicitly typecasts it to just float precision (i.e. 6 decimal digits)

avatar image
0

Answer by adrianseeley · May 17, 2015 at 02:56 PM

If you came here looking for how to use UInt64 or UInt32 in Unity - most likely as a result of getting a compiler error when using one; Then simply include:

 using System;

At the top of your script and the errors should go away.

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

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

2 People are following this question.

avatar image avatar image

Related Questions

More Vector3 decimal precision in the Console? 3 Answers

Set Precision of Scientific Notation 1 Answer

Convert double to float for Vector3 1 Answer

Custom World Coordinate system? Changing Space.World? 2 Answers

Render Numerical Values w/o Using GUI.* 1 Answer


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