Need a custom currency format to use with String.Format

前端 未结 5 668
無奈伤痛
無奈伤痛 2021-01-04 05:55

I\'m trying to use String.Format(\"{0:c}\", somevalue) in C# but am having a hard time figuring out how to configure the output to meet my needs. Here are my needs:

5条回答
  •  迷失自我
    2021-01-04 06:09

    The "C" currency formats are great until you need a blank for 0. Here are two ways, one mentioned above, similar to the ones that I use that give you the blank for 0:

    // one way
    string.Format("{0:$#,##0.00;($#,##0.00);''}", somevalue)
    
    // another way
    somevalue.ToString("$#,##0.00;($#,##0.00);''")
    

    The second technique feels more "fluent", if you like that style of code (as I do).

提交回复
热议问题