C # number shaper for amount of money how to convert int 12333545 = 12 333 545

What is the easiest and fastest way to convert a string or int to money format

i means integer = 21232221 when in the form = 21,232,221

C # 4.0 asp.net 4.0

Thank you

direct answer

public static string NumberShaper(int irNumber) { return (irNumber.ToString("N", System.Globalization.CultureInfo.InvariantCulture).Replace(".00","")); } 
+4
source share
3 answers

You can simply call ToString with the selected format string.

For example, in your case:

 int value = 21232221; string result = value.ToString("N"); 

As a result, the value 21,232,221 will be displayed as a result. For formatting, use "C" as the currency (although this will add the specified currency, that is: $). There are many options for format strings — see here for details.

+5
source

Use formatting:

 string formatted = 21232221.ToString("N0"); 
+5
source
 int money = 21232221; var output = money.ToString("c"); 
+2
source

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


All Articles