Ancient Ancient - 9 months ago 62
C# Question

Remove $ from .ToString("{0:C}") formatted number

Basically I am formatting numbers like this

@String.Format("{0:C}", Model.Price)

The result is $2,320,000.00

My desired result, however, is
just without
, respectively. How can I attain this, while still taking advantage of .nets localization handling?


and what if i want that change my class so that when ever a person try to get
, he gets this kind of formatted price . Here is my class

public class Listing : DomainObject
public decimal Price { get; set; }
public decimal Commission { get; set; }

Answer Source

Use N instead of C as your format specifier:

@String.Format("{0:N}", Model.Price)

"C" or "c" Currency Result: A currency value.

123.456 ("C", en-US) -> $123.46

"N" or "n" Number Result: Integral and decimal digits, group separators, and a decimal

1234.567 ("N", en-US) -> 1,234.57

I.e. you were getting a currency symbol because you were asking for one.