How do I display a decimal value to 2 decimal places?

前端 未结 17 2172
没有蜡笔的小新
没有蜡笔的小新 2020-11-21 23:24

When displaying the value of a decimal currently with .ToString(), it\'s accurate to like 15 decimal places, and since I\'m using it to represent dollars and ce

17条回答
  •  遇见更好的自我
    2020-11-22 00:01

    If you just need this for display use string.Format

    String.Format("{0:0.00}", 123.4567m);      // "123.46"
    

    http://www.csharp-examples.net/string-format-double/

    The "m" is a decimal suffix. About the decimal suffix:

    http://msdn.microsoft.com/en-us/library/364x0z75.aspx

提交回复
热议问题