Format a double value like currency but without the currency sign (C#)

后端 未结 9 931
無奈伤痛
無奈伤痛 2020-12-25 10:07

I feed a textbox a string value showing me a balance that need to be formatted like this:

###,###,###,##0.00

I could use the value.ToString

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-25 10:19

    This simple solution works for me with US currency.

    If not needing international currency support use this and replace the $ with the currency symbol(s) to be removed:

    // for USD
    string result = currentBalance.ToString("C").Replace("$", "")
    

    or

    // for EUR
    string result = currentBalance.ToString("C").Replace("€", "")
    

提交回复
热议问题