How to convert price by format

I ran into a pricing problem. I need to format a price entry like XXXX.YY. The problem is that the input price can be in the form XXX, YY in Europe or XX, XXX.YY, if we talk about large numbers.

Is there JS or C # lib there?

thank

+3
source share
3 answers

for american / british format:

Double.Parse("123,456.78", new CultureInfo("en-US"));

for German format:

Double.Parse("123.456,78", new CultureInfo("de-DE"));

Tip. If you store / read data from a file / database, etc., it is usually recommended to use CultureInfo.InvariantCulture

+1
source

Decimal.Parse, Double.Parse, . ( Decimal ..)

, MDSN:

s NumberFormatInfo, . . CurrentInfo. , Decimal.Parse(String, IFormatProvider) Decimal.Parse(String, NumberStyles, IFormatProvider).

, .NET " " . Windows / " " .

+2
Double.Parse("123,456.78")

will work in c #

http://msdn.microsoft.com/en-us/library/7yd1h1be.aspx

Then ToString in the desired format:

String.Format("£{0:##.##}", number);
0
source

Source: https://habr.com/ru/post/1761289/


All Articles