I'm currently working on an ASP.NET MVC 4.6 application. I try to format a Decimal?
property to a correct string format.
My property looks like this:
public decimal? Amount{ get; set; }
The data from the database looks like this: 10000,99
My desired outpout should actually be: € 10.001
no decimal values and no , (comma) is allowed.
In my Razor view I currently use:
@String.Format("{0:N0}", Model.Amount)
This works almost fine, though I get this result: € 10 000 which is wrong unfortunately.
Do you know hot to solve this in ASP.NET MVC Razor? Desired output € 10.001
Thank you!!!!
String.Format()
has an overload which accepts IFormatProvider
. Simply pass the desired number format there:
var c = new System.Globalization.CultureInfo(""); // create InvariantCulture
c.NumberFormat.NumberGroupSeparator = ".";
var s = String.Format(c, "{0:N0}", 10000.99);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.