So I was experimenting with long numbers and E+ showed up when I displayed it on UI text. How can I remove it?.
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.