Double string.format

后端 未结 5 725
北恋
北恋 2021-01-07 18:49

I have some double values I want to convert to a string with this pattern:

0.xx or x.xx

Currently I have try this:

double.T         


        
相关标签:
5条回答
  • 2021-01-07 19:00

    just use

    myDouble.ToString("0.00")
    

    that should do the trick

    0 讨论(0)
  • 2021-01-07 19:00
    String.Format("{0:0.00}", 111.0);
    
    0 讨论(0)
  • 2021-01-07 19:09

    use following :

    myDouble.ToString("N2")
    
    0 讨论(0)
  • 2021-01-07 19:13
    myDouble.ToString("N2")
    

    should also work.

    Have a look at

    MSDN: Custom Numeric Format Strings

    MSDN: Standard Numeric Format Strings

    0 讨论(0)
  • 2021-01-07 19:14

    Put a zero in front of the decimal separator:

    double.ToString("0.#0");
    

    This will always include the digit, in contrast to # which makes it optional.

    0 讨论(0)
提交回复
热议问题