# Converting a Number in Currency Format For Different Cultures

In this article we will learn how to display a number in its currency format with respect to a country. When we want to display a number in its respective country's currency format, we format the string in the currency format and get the currency symbol of a specific country using the "CultureInfo" class available in .Net. To use the CultureInfo class, we need to include the "System.Globalization" Namespace in our program.

The "C" format specifier converts a number to a string that represents a currency amount. The precision specifier indicates the desired number of decimal places in the result string. If the precision specifier is omitted then the default precision is used (the default value is 2).

If the value to be formatted has more than the specified or the default number of decimal places then the fractional value is rounded in the result string. If the value to the right of the number of the specified decimal places is 5 or greater then the last digit in the result string is rounded away from zero.

Here is code showing how to convert a number to its corresponding currency format for a respective country:

using System;

using System.Globalization;

namespace CurrencyFormatter

{

class Program

{

static void Main(string[] args)

{

double value = 5623345.6789;

//For Current Culture

Console.WriteLine("\n--------- Displaying Currency in Current Culture ---------------\n");

// By default, single letter C displays currency upto two decimal digits

Console.WriteLine(value.ToString("C", CultureInfo.CurrentCulture));

// C2 displays currency upto two digits

Console.WriteLine(value.ToString("C2", CultureInfo.CurrentCulture));

// C3 displays currency upto three digits

Console.WriteLine(value.ToString("C3", CultureInfo.CurrentCulture));

// C4 displays currency upto four digits

Console.WriteLine(value.ToString("C4", CultureInfo.CurrentCulture));

// C5 displays currency upto five digits

Console.WriteLine(value.ToString("C5", CultureInfo.CurrentCulture));

//For Japan

Console.WriteLine("\n--------- Dispalying Currency for Japan ---------------\n");

Console.WriteLine(value.ToString("C", CultureInfo.CreateSpecificCulture("ja-JP")));

//For Denmark

Console.WriteLine("\n--------- Dispalying Currency for Denmark ---------------\n");

Console.WriteLine(value.ToString("C",

CultureInfo.CreateSpecificCulture("da-DK")));

//For India

Console.WriteLine("\n--------- Dispalying Currency for India ---------------\n");

Console.WriteLine(value.ToString("C",

CultureInfo.CreateSpecificCulture("en-IN")));

Console.Read();

}

}

}

The result string is affected by the formatting information of the current NumberFormatInfo object. As per MSDN, the following table lists the NumberFormatInfo properties that control the formatting of the returned string.

 NumberFormatInfo property Description CurrencyPositivePattern Defines the placement of the currency symbol for positive values. CurrencyNegativePattern Defines the placement of the currency symbol for negative values, and specifies whether the negative sign is represented by parentheses or the NegativeSign property. NegativeSign Defines the negative sign used if CurrencyNegativePattern indicates that parentheses are not used. CurrencySymbol Defines the currency symbol. CurrencyDecimalDigits Defines the default number of decimal digits in a currency value. This value can be overridden by using the precision specifier. CurrencyDecimalSeparator Defines the string that separates integral and decimal digits. CurrencyGroupSeparator Defines the string that separates groups of integral numbers. CurrencyGroupSizes Defines the number of integer digits that appear in a group.

Now let us see some of the important properties of the "NumberFormatInfo" object in the following sections.

How to group the numbers using NumberFormatInfo.CurrencyGroupSizes property

It is used to get or set the number of digits in each group to the left of the decimal in currency values. To set grouping in a number, we assign this property to an integer array having a required grouping.

For example, if the array contains {2, 4, 3} then the digits are grouped similar to \$55, 555, 555, 554, 4443, 33.00". If the array contains {2, 4, 0} then the digits are grouped similar to \$55555555554, 4443, 33.00". That means that the grouping of digits starts from the left corresponding to array elements. If the digits in a number are greater than the sum of the array elements then the remaining digits in the number are grouped (from left to right) as per the value of the last element in the array, provided that the element is non-zero. If the last element in the array is Zero then grouping won't take place for the remaining digits.

The following code demonstrates how to set digits grouping in a number:

using System;

using System.Globalization;

class NumberFormatInfoSample

{

public static void Main()

{

// Gets a NumberFormatInfo associated with the USA culture.

NumberFormatInfo myNumberFormatInfo = new CultureInfo("en-US", false).NumberFormat;

// Displays a value with the default separator

long myInt = 55555555554444333;

Console.WriteLine("\nDisplays a value with the default separator ");

Console.WriteLine(myInt.ToString("C", myNumberFormatInfo));

// Displays the same value with different groupings.

int[] mySizes1 = { 2, 4, 3 };

int[] mySizes2 = { 2, 4, 0 };

myNumberFormatInfo.CurrencyGroupSizes = mySizes1;

Console.WriteLine("\nDisplays the same value with different group {2,4,3}  ");

Console.WriteLine(myInt.ToString("C", myNumberFormatInfo));

myNumberFormatInfo.CurrencyGroupSizes = mySizes2;

Console.WriteLine("\nDisplays the same value with different group {2,4,0}  ");

Console.WriteLine(myInt.ToString("C", myNumberFormatInfo));

Console.Read();

}

}

It produces output
as in the following:

The following code shows how to set a group separator symbol using the NumberFormatInfo.CurrencyGroupSeparator property:

using System;

using System.Globalization;

class NumberFormatInfoSample

{

public static void Main()

{

// Gets a NumberFormatInfo associated with the USA culture.

NumberFormatInfo myNumberFormatInfo = new CultureInfo("en-US", false).NumberFormat;

Int64 myInt = 5674433277865454;

// Displays a value with following grouping.

int[] mySizes1 = { 2, 4, 6 };

myNumberFormatInfo.CurrencyGroupSizes = mySizes1;

Console.WriteLine("\nDisplays a value with default seperator symbol (,) : ");

Console.WriteLine(myInt.ToString("C", myNumberFormatInfo));

myNumberFormatInfo.CurrencyGroupSeparator = "_";

Console.WriteLine("\nDisplays the same value with seperator symbol (_) : ");

Console.WriteLine(myInt.ToString("C", myNumberFormatInfo));

Console.Read();

}

}

The code above produces the following output:

For your reference, here is a table of countries and their Culture Info Codes:

 Country Two Letter Country Code Three Letter Country Code Language Two Letter Lang Code Three Letter Lang Code CultureInfo Code IR IRN Persian fa fas fa-IR Afghanistan AF AFG Pashto ps pus ps-AF Afghanistan AF AFG Dari prs prs prs-AF Albania AL ALB Albanian sq sqi sq-AL Algeria DZ DZA Arabic ar ara ar-DZ Argentina AR ARG Spanish es spa es-AR Armenia AM ARM Armenian hy hye hy-AM Australia AU AUS English en eng en-AU Austria AT AUT German de deu de-AT Bahrain BH BHR Arabic ar ara ar-BH Bangladesh BD BGD Bengali bn bng bn-BD Basque ES ESP Basque eu eus eu-ES Belarus BY BLR Belarusian be bel be-BY Belgium BE BEL French fr fra fr-BE Belgium BE BEL Dutch nl nld nl-BE Belize BZ BLZ English en eng en-BZ Bolivarian Republic of Venezuela VE VEN Spanish es spa es-VE Bolivia BO BOL Quechua quz qub quz-BO Bolivia BO BOL Spanish es spa es-BO Brazil BR BRA Portuguese pt por pt-BR Brunei Darussalam BN BRN Malay ms msa ms-BN Bulgaria BG BGR Bulgarian bg bul bg-BG Cambodia KH KHM Khmer km khm km-KH Canada CA CAN French fr fra fr-CA Canada CA CAN English en eng en-CA Caribbean 29 29 English en eng en-029 Catalan ES ESP Catalan ca cat ca-ES Chile CL CHL Mapudungun arn arn arn-CL Chile CL CHL Spanish es spa es-CL Colombia CO COL Spanish es spa es-CO Costa Rica CR CRI Spanish es spa es-CR Croatia HR HRV Croatian hr hrv hr-HR Cyrillic, Azerbaijan AZ AZE Azeri az aze az-Cyrl-AZ Cyrillic, Bosnia and Herzegovina BA BIH Serbian sr srn sr-Cyrl-BA Cyrillic, Bosnia and Herzegovina BA BIH Bosnian bs bsc bs-Cyrl-BA Cyrillic, Mongolia MN MNG Mongolian mn mon mn-MN Cyrillic, Montenegro ME MNE Serbian sr srp sr-Cyrl-ME Cyrillic, Serbia RS SRB Serbian sr srp sr-Cyrl-RS Cyrillic, Serbia and Montenegro (Former CS SCG Serbian ) sr srp sr-Cyrl-CS Cyrillic, Tajikistan TJ TAJ Tajik tg tgk tg-Cyrl-TJ Cyrillic, Uzbekistan UZ UZB Uzbek uz uzb uz-Cyrl-UZ Czech Republic CZ CZE Czech cs ces cs-CZ Denmark DK DNK Danish da dan da-DK Dominican Republic DO DOM Spanish es spa es-DO Ecuador EC ECU Quechua quz que quz-EC Ecuador EC ECU Spanish es spa es-EC Egypt EG EGY Arabic ar ara ar-EG El Salvador SV SLV Spanish es spa es-SV Estonia EE EST Estonian et est et-EE Ethiopia ET ETH Amharic am amh am-ET Faroe Islands FO FRO Faroese fo fao fo-FO Finland FI FIN Finnish fi fin fi-FI Finland FI FIN Swedish sv swe sv-FI Finland FI FIN Sami, Northern se smg se-FI Finland FI FIN Sami, Skolt sms sms sms-FI Finland FI FIN Sami, Inari smn smn smn-FI Former Yugoslav Republic of Macedonia MK MKD Macedonian mk mkd mk-MK France FR FRA French fr fra fr-FR France FR FRA Breton br bre br-FR France FR FRA Occitan oc oci oc-FR France FR FRA Corsican co cos co-FR France FR FRA Alsatian gsw gsw gsw-FR Galician ES ESP Galician gl glg gl-ES Georgia GE GEO Georgian ka kat ka-GE Germany DE DEU German de deu de-DE Germany DE DEU Upper Sorbian hsb hsb hsb-DE Germany DE DEU Lower Sorbian dsb dsb dsb-DE Greece GR GRC Greek el ell el-GR Greenland GL GRL Greenlandic kl kal kl-GL Guatemala GT GTM K'iche qut qut qut-GT Guatemala GT GTM Spanish es spa es-GT Honduras HN HND Spanish es spa es-HN Hungary HU HUN Hungarian hu hun hu-HU Iceland IS ISL Icelandic is isl is-IS India IN IND Hindi hi hin hi-IN India IN IND Bengali bn bng bn-IN India IN IND Punjabi pa pan pa-IN India IN IND Gujarati gu guj gu-IN India IN IND Oriya or ori or-IN India IN IND Tamil ta tam ta-IN India IN IND Telugu te tel te-IN India IN IND Kannada kn kan kn-IN India IN IND Malayalam ml mym ml-IN India IN IND Assamese as asm as-IN India IN IND Marathi mr mar mr-IN India IN IND Sanskrit sa san sa-IN India IN IND Konkani kok kok kok-IN India IN IND English en eng en-IN Indonesia ID IDN Indonesian id ind id-ID Iraq IQ IRQ Arabic ar ara ar-IQ Ireland IE IRL Irish ga gle ga-IE Ireland IE IRL English en eng en-IE Islamic Republic of Pakistan PK PAK Urdu ur urd ur-PK Israel IL ISR Hebrew he heb he-IL Italy IT ITA Italian it ita it-IT Jamaica JM JAM English en eng en-JM Japan JP JPN Japanese ja jpn ja-JP Jordan JO JOR Arabic ar ara ar-JO Kazakhstan KZ KAZ Kazakh kk kaz kk-KZ Kenya KE KEN Kiswahili sw swa sw-KE Korea KR KOR Korean ko kor ko-KR Kuwait KW KWT Arabic ar ara ar-KW Kyrgyzstan KG KGZ Kyrgyz ky kir ky-KG Lao P.D.R. LA LAO Lao lo lao lo-LA Latin, Algeria DZ DZA Tamazight tzm tzm tzm-Latn-DZ Latin, Azerbaijan AZ AZE Azeri az aze az-Latn-AZ Latin, Bosnia and Herzegovina BA BIH Croatian hr hrb hr-BA Latin, Bosnia and Herzegovina BA BIH Bosnian bs bsb bs-Latn-BA Latin, Bosnia and Herzegovina BA BIH Serbian sr srs sr-Latn-BA Latin, Canada CA CAN Inuktitut iu iku iu-Latn-CA Latin, Montenegro ME MNE Serbian sr srp sr-Latn-ME Latin, Nigeria NG NGA Hausa ha hau ha-Latn-NG Latin, Serbia RS SRB Serbian sr srp sr-Latn-RS Latin, Serbia and Montenegro (Former CS SCG Serbian ) sr srp sr-Latn-CS Latin, Uzbekistan UZ UZB Uzbek uz uzb uz-Latn-UZ Latvia LV LVA Latvian lv lav lv-LV Lebanon LB LBN Arabic ar ara ar-LB Libya LY LBY Arabic ar ara ar-LY Liechtenstein LI LIE German de deu de-LI Lithuania LT LTU Lithuanian lt lit lt-LT Luxembourg LU LUX Luxembourgish lb ltz lb-LU Luxembourg LU LUX German de deu de-LU Luxembourg LU LUX French fr fra fr-LU Malaysia MY MYS Malay ms msa ms-MY Malaysia MY MYS English en eng en-MY Maldives MV MDV Divehi dv div dv-MV Malta MT MLT Maltese mt mlt mt-MT Mexico MX MEX Spanish es spa es-MX Mohawk CA CAN Mohawk moh moh moh-CA Monaco MC MCO French fr fra fr-MC Morocco MA MAR Arabic ar ara ar-MA Nepal NP NPL Nepali ne nep ne-NP Netherlands NL NLD Dutch nl nld nl-NL Netherlands NL NLD Frisian fy fry fy-NL New Zealand NZ NZL Maori mi mri mi-NZ New Zealand NZ NZL English en eng en-NZ Nicaragua NI NIC Spanish es spa es-NI Nigeria NG NGA Yoruba yo yor yo-NG Nigeria NG NGA Igbo ig ibo ig-NG Norway NO NOR Norwegian, Bokmål nb nob nb-NO Norway NO NOR Sami, Northern se sme se-NO Norway NO NOR Norwegian, Nynorsk nn nno nn-NO Norway NO NOR Sami, Lule smj smj smj-NO Norway NO NOR Sami, Southern sma sma sma-NO Oman OM OMN Arabic ar ara ar-OM PRC CN CHN Tibetan bo bod bo-CN PRC CN CHN Yi ii iii ii-CN PRC CN CHN Uyghur ug uig ug-CN Panama PA PAN Spanish es spa es-PA Paraguay PY PRY Spanish es spa es-PY Peru PE PER Quechua quz qup quz-PE Peru PE PER Spanish es spa es-PE Philippines PH PHL Filipino fil fil fil-PH Poland PL POL Polish pl pol pl-PL Portugal PT PRT Portuguese pt por pt-PT Puerto Rico PR PRI Spanish es spa es-PR Qatar QA QAT Arabic ar ara ar-QA Republic of the Philippines PH PHL English en eng en-PH Romania RO ROU Romanian ro ron ro-RO Russia RU RUS Russian ru rus ru-RU Russia RU RUS Tatar tt tat tt-RU Russia RU RUS Bashkir ba bak ba-RU Russia RU RUS Yakut sah sah sah-RU Rwanda RW RWA Kinyarwanda rw kin rw-RW Saudi Arabia SA SAU Arabic ar ara ar-SA Senegal SN SEN Wolof wo wol wo-SN Simplified, PRC CN CHN Chinese zh zho zh-CN Simplified, Singapore SG SGP Chinese zh zho zh-SG Singapore SG SGP English en eng en-SG Slovakia SK SVK Slovak sk slk sk-SK Slovenia SI SVN Slovenian sl slv sl-SI South Africa ZA ZAF Setswana tn tsn tn-ZA South Africa ZA ZAF isiXhosa xh xho xh-ZA South Africa ZA ZAF isiZulu zu zul zu-ZA South Africa ZA ZAF Afrikaans af afr af-ZA South Africa ZA ZAF Sesotho sa Leboa nso nso nso-ZA South Africa ZA ZAF English en eng en-ZA Spain, International Sort ES ESP Spanish es spa es-ES Sri Lanka LK LKA Sinhala si sin si-LK Sweden SE SWE Swedish sv swe sv-SE Sweden SE SWE Sami, Northern se smf se-SE Sweden SE SWE Sami, Lule smj smk smj-SE Sweden SE SWE Sami, Southern sma smb sma-SE Switzerland CH CHE Romansh rm roh rm-CH Switzerland CH CHE German de deu de-CH Switzerland CH CHE Italian it ita it-CH Switzerland CH CHE French fr fra fr-CH Syllabics, Canada CA CAN Inuktitut iu iku iu-Cans-CA Syria SY SYR Syriac syr syr syr-SY Syria SY SYR Arabic ar ara ar-SY Thailand TH THA Thai th tha th-TH Traditional Mongolian, PRC CN CHN Mongolian mn mon mn-Mong-CN Traditional, Hong Kong S.A.R. HK HKG Chinese zh zho zh-HK Traditional, Macao S.A.R. MO MAC Chinese zh zho zh-MO Traditional, Taiwan TW TWN Chinese zh zho zh-TW Trinidad and Tobago TT TTO English en eng en-TT Tunisia TN TUN Arabic ar ara ar-TN Turkey TR TUR Turkish tr tur tr-TR Turkmenistan TM TKM Turkmen tk tuk tk-TM U.A.E. AE ARE Arabic ar ara ar-AE Ukraine UA UKR Ukrainian uk ukr uk-UA United Kingdom GB GBR Welsh cy cym cy-GB United Kingdom GB GBR Scottish Gaelic gd gla gd-GB United Kingdom GB GBR English en eng en-GB United States US USA English en eng en-US United States US USA Spanish es spa es-US Uruguay UY URY Spanish es spa es-UY Vietnam VN VNM Vietnamese vi vie vi-VN Yemen YE YEM Arabic ar ara ar-YE Zimbabwe ZW ZWE English en eng en-ZW

Up Next
Ebook Download
View all
Learn
View all