Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have a number 2879068.
I want to display it in currency format as like 28,79,068 in C#.
Can any one help me?
Posted
Updated 25-Nov-21 2:56am
v2
Comments
Toli Cuturicu 9-Jan-11 3:20am    
Correct format should be 2,879,068 though.

string.Format("{0:C}", 0.02);

Just my 2ct's worth

Regards
Espen Harlinn
 
Share this answer
 
Comments
fjdiewornncalwe 8-Jan-11 12:58pm    
5... because I like the pun...
Espen Harlinn 8-Jan-11 13:01pm    
Good, it was purely intentional ...
Nuri Ismail 8-Jan-11 13:18pm    
Good call. Have a 5.
See here[^].
 
Share this answer
 
Comments
Nuri Ismail 8-Jan-11 13:19pm    
Good link.
Hi,

The following code will display the currency using the machine local settings, so if the PC on which the application runs is outside of the US you might have surprises... ie £3.44 or 445.00 EUR etc...

price = string.Format("{0:C}");

in order to avoid this issue, it would be safer to use the following code:
using System.Globalization;
...
CultureInfo cultureInfo = new CultureInfo("en-US");
price = string.Format(cultureInfo,"{0:C}",myRate)

Hope it helps.

Valery.
 
Share this answer
 
Comments
Espen Harlinn 8-Jan-11 17:09pm    
5+ true enough, if you want your application to show the number in $s all the time.
I got the perfect answer for it.

here is the code for it
int iValue = 2879068;

string sValue1 = String.Format("{0:C}", iValue);

string sValue2 = String.Format("{0:#,#.}", iValue);
 
Share this answer
 
Comments
Espen Harlinn 9-Jan-11 11:54am    
Good for you! consider using a decimal for currency, or double - an int sort of rubs me the wrong way ...
public static string ConvertStringToRupee(string Amount)
    {
        float num = float.Parse(Amount);
        NumberFormatInfo provider = new NumberFormatInfo
        {
            CurrencyGroupSeparator = ",",
            CurrencyGroupSizes = new int[] { 3, 2 },
            CurrencySymbol = ""
        };
        return num.ToString("N", provider);
    }
 
Share this answer
 
Comments
CHill60 9-Nov-21 5:26am    
Reason for my vote of 1 - when I run your code with the OP's example I get the result 2,879,068.00 instead of 28,79,068. There are far easier ways to get the same, wrong, result. Perhaps you wanted something like this
	public static string ConvertStringToRupee(float Amount)
    {
		NumberFormatInfo nfi = new CultureInfo("en-IN").NumberFormat;
		nfi.CurrencySymbol = "";
		nfi.NumberDecimalDigits = 0;
        return Amount.ToString("N", nfi);
    }
It can be achieved in Two ways:

String.Format() method where {0:C} format specifier is used.

ToString() method converts any data type to string and format specifier C is used to convert the value to currency format.

C#
using System;

namespace Samplecsharp
{
    class Program
    {
        static void Main(string[] args)
        {
            decimal amt = 1234567;

            //String.Format() method
            string amtString = String.Format("{0:C}", amt);

            //ToString() method
            string amtToString = amt.ToString("C");

            Console.WriteLine(amtString);
            Console.WriteLine(amtToString);
        }
    }
}

Output:
12,34,567.00
 
Share this answer
 
Comments
CHill60 25-Nov-21 9:07am    
Reasons for my vote of 1:
- the String.Format method has already been mentioned in 3 previous solutions
- When I run your code I get $2,879,068.00, which is incorrect - this is because you, like most of the other solutions, have assumed that the correct Culture is already in play. See my comment to Solution 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900