What is the easiest and fastest way of converting string or int to the money format
i mean like an integer = 21232221 when shaped = 21,232,221
c# 4.0 asp.net 4.0
thank you
the direct answer
public static string NumberShaper(int irNumber)
{
return (irNumber.ToString("N", System.Globalization.CultureInfo.InvariantCulture).Replace(".00",""));
}
You can just call ToString
with the format string of choice.
For example, in your case:
int value = 21232221;
string result = value.ToString("N");
This will place 21,232,221 as the value in result. To format as currency, use "C"
(though this will add the currency specified, ie: $). There are many options for format strings - for details, see here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With