Why Is ToString() Rounding My Double Value?

前端 未结 5 959
别那么骄傲
别那么骄傲 2020-12-03 17:17

How do I prevent my double value from being rounded when converting to a string? I have tried both Convert.ToString and ToString() with the same r

5条回答
  •  一生所求
    2020-12-03 17:51

    Try something like

    myDouble.ToString("R")
    

    See also The Round-trip ("R") Format Specifier:

    The round-trip ("R") format specifier guarantees that a numeric value that is converted to a string will be parsed back into the same numeric value.

提交回复
热议问题