Search code examples
c#asp.net-coreasp.net-core-mvcasp-net-core-spa-services

Represent decimal first with point, then comma


I found plenty of solutions with first comma and then point, and I want something like this: 133.000,00

What I tried so far: @item.Price.ToString("C3", System.Globalization.CultureInfo.CreateSpecificCulture("da-DK"))

and

@String.Format("{0:#.##0,######}", item.Price)

In second formatting I am only getting 133000.00


Solution

  • You probably mean (after var culture = CultureInfo.CreateSpecificCulture("da-DK");)

    var s = price.ToString("#,##0.00####", culture);
    

    or:

    var s = string.Format(culture, "{0:#,##0.00####}", price);
    

    In both cases you need to pass in the culture to use, and: . in the format string means "the culture's decimal point token", and , in the format string means "the culture's thousands separator token". Note I used .00## at the end because you seem to want two decimal places even if they are zeros.