Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 767
Serlok Avatar asked Mar 07 '19 11:03

Serlok


Video Answer


1 Answers

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.

like image 138
Marc Gravell Avatar answered Oct 11 '22 11:10

Marc Gravell