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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -