- Home /
how to remove E+ in long numbers.
So I was experimenting with long numbers and E+ showed up when I displayed it on UI text. How can I remove it?.
Answer by Bunny83 · Dec 31, 2021 at 12:27 PM
Well, by default ToString for floats uses a 7 digit format (I think it's "G7"). If the lenght of the number exceeds 7 characters it switches to scientific notation. This makes sense for two reasons: First of all a float has roughly an accuracy of 7 significant decimal digits. So values larger that that can't really represent the one's column anymore. Over here I posted a table how the precision of floats degrade with the size of the numbers. The other reason is that floating point numbers could grow up to 38 digits (a double up to 308 digits) and for almost all purposes it makes no sense to write out such long numbers.
Anyways, if you really just want to display large numbers with their best decimal expansion, you can always use a different format specifier. For example using .ToString("G30")
would display up to 30 digits before switching to scientific / exponential notation. There are also other format specifiers for different purposes like currency. Though the exact format of all of them depends on the used culture setting. Keep in mind that about half the world is using a "comma" ,
as decimal point while the other half uses the "dot" .
. It gets even more complicated when it comes to grouping in different cultures.
C# / .NET specifically has an invariant culture that currently matches more or less the english culture setting but it will never change in the future while the individual cultures of countries can change over time. So it depends on the usecase what you want to use when. If it's for displaying numbers to the user, using the local culture (which is the default) is usually the best because numbers are formatted the way they are used to. However if the number should be serialized / stored or send over to another machine on the world, it's always better to use the invariant culture. Otherwise information generated / stored on one machine could not be read properly on another. Though, as I said, this all depends on the usecase.
Great answer. I am wondering, if OP's referring to the default behavior of built-in components and drawers, would this be affected by modifying windows' region settings? If that's linked to the .net default culture... can this specific property be set somehow in the system?
The .NEt culture system uses the systems culture settings. So yes, if you're on windows it should use the settings that you set in the windows config. Though I don't think there is a specific setting for each of the format strings. Though there are general settings for the decimal point and grouping character. It's quite hidden in Win10 under 3 or 4 layers in the region settings.
I can remember that in the past I manually changed the decimal point from comma (german culture) to a dot because it was just annoying in various places ^^. Since 90 - 95% of what I do is related to program$$anonymous$$g it just made more sense that way.
Your answer
![](https://koobas.hobune.stream/wayback/20220613051117im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Text shows on Even numbers, then another text shows on Odd numbers. 0 Answers
Graphic problem with UI Text 2 Answers
New UI: change text 2 Answers