How to convert string to Indian Money format?

I am trying to convert a string to the "Indian money" format, as if the input was "1234567", then the output should appear as "12,34,567"

I wrote the following code, but did not give the expected result.

 CultureInfo hindi = new CultureInfo("hi-IN");
 string text = string.Format(hindi, "{0:c}", fare);
 return text;

can someone tell me how to do this?

+6
source share
2 answers

If fare- any of the int, long, decimal, floator double, then I get the expected conclusion:

₹ 12,34,567.00.

, fare string; string.Format: : . : ( , , , ), ; :

// here we assume that `fare` is actually a `string`
string fare = "1234567";
decimal parsed = decimal.Parse(fare, CultureInfo.InvariantCulture);
CultureInfo hindi = new CultureInfo("hi-IN");
string text = string.Format(hindi, "{0:c}", parsed);

; :

string text = string.Format(hindi, "{0:#,#}", value);
+13

String.Format( "0: C0" ) .

, , numberformatinfo

-

: , :

var cultureInfo = new CultureInfo("hi-IN")
var numberFormatInfo = (NumberFormatInfo)cultureInfo.NumberFormat.Clone();
numberFormatInfo.CurrencySymbol = "";

var price = 1234567;
var formattedPrice = price.ToString("0:C0", numberFormatInfo); // Output: "12,34,567"
0

All Articles