I am trying to convert a double value 9007199254740992.0to a string.
But there seems to be a rounding error (last 2 become 0):
(9007199254740992.0).ToString("#") // Returns "9007199254740990"
(9007199254740992.0).ToString() // Returns"9.00719925474099E+15"
At first I thought that maybe the number could not be represented as double. But it is possible. This can be seen by dropping it to the end, and then converting it to a string.
((long)9007199254740991.0).ToString()
((long)9007199254740992.0).ToString()
In addition, I found that if I use the "R" format , it works.
(9007199254740992.0).ToString("R") // Returns "9007199254740992"
Can someone explain why it ToString("#")doesn't return double with integer part with full precision?
source
share