c# - string.format(format,doubleValue) , precision lost -
i have double value:
var value = 52.30298270000003 and when convert string, losses precision:
var str = string.format("{0} text...", value); console.writeline(str); // output: 52.3029827 the number of precision on double value may changed @ run-time. how can force string.format method use precision?
you want use r format specifier
from msdn
result: string can round-trip identical number.
supported by: single, double, , biginteger.
precision specifier: ignored.
more information: the round-trip ("r") format specifier.
string.format("{0:r} text...", value) will give
52.30298270000003 text...
Comments
Post a Comment