I'm porting an app from .NET to the Mono Runtime, and at one point in the code I can see that a float has the value 158136.422. My understanding of float was that it was 7 digit precision, so how is that number acceptable? Mono trims it to 7 digits as I'd expect.
If in C# I do
float f = 158136.422f;
It gets rounded to 158136.4.
When you write this code:
float f = 158136.422f;
The exact value assigned to f is 158136.421875.
How many digits are output in a string representation is a different matter.
When I use:
float f = 158136.422f;
Console.WriteLine(f);
Console.WriteLine(f.ToString("r"));
I get results of:
158136.4
158136.422
on both Mono and .NET.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With