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 /
avatar image
0
Question by jeffreywarf · Feb 01, 2016 at 10:38 PM · numberprecisionlarge

Set Precision of Scientific Notation

What I mean is, in the inspector, it will say something like "2.56739276596e74" or something, how could i simplify this to just, like, 2.57e74? Is there a simple command you can give like for removing scientific notation ("n0")? or does it require some coding magic that will take a while?

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
1
Best Answer

Answer by Eno-Khaon · Feb 01, 2016 at 11:14 PM

According to Microsoft's page on Standard Numeric Format Strings, you should be able to specify the apparent accuracy of scientific notation using the "G" modifier.

In this case, "G2" should give you only two digits of accuracy to match your example.

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 jeffreywarf · Feb 03, 2016 at 04:55 AM 0
Share

how simple and elegant. Thanks. I tested it out and it works perfectly.

avatar image
2

Answer by Bunny83 · Feb 02, 2016 at 12:11 AM

Well, unfortunately there's nothing build into the Editor that would allow you to change the default behaviour. The editor uses internal static string fields which contains a format string which is used by FloatField and "DoubleField".

 // inside UnityEditor.EditorGUI
 internal static string kFloatFieldFormatString = "g7";
 internal static string kDoubleFieldFormatString = "g15";

The problem is, when you would change those default format strings (using reflection or something like that) it would affect not only how the values are displayed. Since those are edit-fields the actual value would be restricted to the given range when you edit the field.

You can however customize how a field is displayed / treated by implementing either a custom inspector for your class, or a PropertyDrawer to customize how a single field is handled. The numberfields (FloatField and DoubleField) are quite complicated and as said they don't allow to pass a custom format string. You can either replicate them yourself, or create a simple wrapper around them which uses reflection to change those internal format strings temporarily.

If you want to know how the FloatField / DoubleField is implemented, you can use "ILSpy" or any other .NET / Mono reflector and open the UnityEditor.dll.

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 jeffreywarf · Feb 03, 2016 at 04:56 AM 0
Share

that was very informative about how the engine works, I appreciate the information.

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

35 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

Related Questions

Large number of objects problem 1 Answer

Efficient visualization of 100000+ simple objects 1 Answer

High precision numbers 2 Answers

how to i increase a number temporally 1 Answer

bool to int? (false = 0, true = 1) Conversion possible? Or manually set int to 0/1? 2 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