8

For complicated reasons I need to find out which symbol (dot or comma) is used for Decimals in the current User's Locale.

Is there any way to find that out using Apex or formulas?

2
  • Do you explicitly have to know the actual character or is it enough to make sure your output of a number correctly matches what their locale states it should be? Commented Nov 28, 2013 at 12:15
  • I think this topic at Wikipedia could help you. Commented Nov 28, 2013 at 12:29

2 Answers 2

5

Sadly the UserInfo class does not yet expose this information, so it must be derived. You can use this approach in Apex, leveraging the fact that the Decimal.format method is locale sensitive.

Returns the String value of this Decimal using the locale of the context user.

    Decimal value = 1000.10;
    String formattedValue = value.format();
    String thousandSep = formattedValue.substring(1,2);
    String decimalSep = formattedValue.substring(5,6);
2

Salesforce supports 186 different locales, but do not enumerate the decimal mark or thousands separator for all of them.

For server-side code you can use Andrew Fawcett's method. (Just watch out for Armenian language / locale, which uses no thousands separator; you'll get 0 instead of ,)

For client-side code, you'd need a predefined list:

{
    "sq":           ",", // Albanian
    "sq_AL":        ",", // Albanian (Albania)
    "ar":           ".", // Arabic
    "ar_BH":        ".", // Arabic (Bahrain)
    "ar_EG":        ".", // Arabic (Egypt)
    "ar_JO":        ".", // Arabic (Jordan)
    "ar_KW":        ".", // Arabic (Kuwait)
    "ar_LB":        ".", // Arabic (Lebanon)
    "ar_QA":        ".", // Arabic (Qatar)
    "ar_SA":        ".", // Arabic (Saudi Arabia)
    "ar_AE":        ".", // Arabic (United Arab Emirates)
    "hy":           ",", // Armenian
    "hy_AM":        ",", // Armenian (Armenia)
    "az_AZ":        ",", // Azerbaijani (Azerbaijan)
    "eu":           ",", // Basque
    "eu_ES":        ",", // Basque (Spain)
    "be_BY":        ",", // Belarusian (Belarus)
    "bn_BD":        ".", // Bengali (Bangladesh)
    "bs":           ",", // Bosnian
    "bs_BA":        ",", // Bosnian (Bosnia and Herzegovina)
    "bg":           ",", // Bulgarian
    "bg_BG":        ",", // Bulgarian (Bulgaria)
    "ca":           ",", // Catalan
    "ca_ES_EURO":   ",", // Catalan (Spain,Euro)
    "ca_ES":        ",", // Catalan (Spain)
    "zh":           ".", // Chinese
    "zh_CN_PINYIN": ".", // Chinese (China, Pinyin Ordering)
    "zh_CN_STROKE": ".", // Chinese (China, Stroke Ordering)
    "zh_CN":        ".", // Chinese (China)
    "zh_HK_STROKE": ".", // Chinese (Hong Kong SAR China, Stroke Ordering)
    "zh_HK":        ".", // Chinese (Hong Kong SAR China)
    "zh_MO":        ".", // Chinese (Macau SAR China)
    "zh_SG":        ".", // Chinese (Singapore)
    "zh_TW_STROKE": ".", // Chinese (Taiwan, Stroke Ordering)
    "zh_TW":        ".", // Chinese (Taiwan)
    "hr":           ",", // Croatian
    "hr_HR":        ",", // Croatian (Croatia)
    "cs":           ",", // Czech
    "cs_CZ":        ",", // Czech (Czech Republic)
    "da":           ",", // Danish
    "da_DK":        ",", // Danish (Denmark)
    "nl":           ",", // Dutch
    "nl_BE":        ",", // Dutch (Belgium)
    "nl_NL":        ",", // Dutch (Netherlands)
    "nl_SR":        ",", // Dutch (Suriname)
    "en_AU":        ".", // English (Australia)
    "en_BB":        ".", // English (Barbados)
    "en_BM":        ".", // English (Bermuda)
    "en_CA":        ".", // English (Canada)
    "en_GH":        ".", // English (Ghana)
    "en_IN":        ".", // English (India)
    "en_ID":        ".", // English (Indonesia)
    "en_IE_EURO":   ".", // English (Ireland,Euro)
    "en_IE":        ".", // English (Ireland)
    "en_MY":        ".", // English (Malaysia)
    "en_NZ":        ".", // English (New Zealand)
    "en_NG":        ".", // English (Nigeria)
    "en_PK":        ".", // English (Pakistan)
    "en_PH":        ".", // English (Philippines)
    "en_SG":        ".", // English (Singapore)
    "en_ZA":        ".", // English (South Africa)
    "en_GB":        ".", // English (United Kingdom)
    "en_US":        ".", // English (United States)
    "et":           ",", // Estonian
    "et_EE":        ",", // Estonian (Estonia)
    "fi":           ",", // Finnish
    "fi_FI_EURO":   ",", // Finnish (Finland,Euro)
    "fi_FI":        ",", // Finnish (Finland)
    "fr":           ",", // French
    "fr_BE":        ",", // French (Belgium)
    "fr_CA":        ",", // French (Canada)
    "fr_FR_EURO":   ",", // French (France,Euro)
    "fr_FR":        ",", // French (France)
    "fr_LU":        ",", // French (Luxembourg)
    "fr_MC":        ",", // French (Monaco)
    "fr_CH":        ".", // French (Switzerland)
    "ka":           ",", // Georgian
    "ka_GE":        ",", // Georgian (Georgia)
    "de":           ",", // German
    "de_AT_EURO":   ",", // German (Austria,Euro)
    "de_AT":        ",", // German (Austria)
    "de_DE_EURO":   ",", // German (Germany,Euro)
    "de_DE":        ",", // German (Germany)
    "de_LU_EURO":   ",", // German (Luxembourg,Euro)
    "de_LU":        ",", // German (Luxembourg)
    "de_CH":        ".", // German (Switzerland)
    "el":           ",", // Greek
    "el_GR":        ",", // Greek (Greece)
    "iw":           ".", // Hebrew
    "iw_IL":        ".", // Hebrew (Israel)
    "hi":           ".", // Hindi
    "hi_IN":        ".", // Hindi (India)
    "hu":           ",", // Hungarian
    "hu_HU":        ",", // Hungarian (Hungary)
    "is":           ",", // Icelandic
    "is_IS":        ",", // Icelandic (Iceland)
    "in":           ",", // Indonesian
    "in_ID":        ",", // Indonesian (Indonesia)
    "ga":           ".", // Irish
    "ga_IE":        ".", // Irish (Ireland)
    "it":           ",", // Italian
    "it_IT":        ",", // Italian (Italy)
    "it_CH":        ".", // Italian (Switzerland)
    "ja":           ".", // Japanese
    "ja_JP":        ".", // Japanese (Japan)
    "kk_KZ":        ",", // Kazakh (Kazakhstan)
    "km_KH":        ",", // Khmer (Cambodia)
    "ky_KG":        ".", // Kirghiz (Kyrgyzstan)
    "ko":           ".", // Korean
    "ko_KR":        ".", // Korean (South Korea)
    "lv":           ",", // Latvian
    "lv_LV":        ",", // Latvian (Latvia)
    "lt":           ",", // Lithuanian
    "lt_LT":        ",", // Lithuanian (Lithuania)
    "lb":           ".", // Luxembourgish
    "lb_LU":        ".", // Luxembourgish (Luxembourg)
    "mk":           ",", // Macedonian
    "mk_MK":        ",", // Macedonian (Macedonia)
    "ms":           ".", // Malay
    "ms_BN":        ",", // Malay (Brunei)
    "ms_MY":        ".", // Malay (Malaysia)
    "mt":           ".", // Maltese
    "mt_MT":        ".", // Maltese (Malta)
    "sh_ME":        ",", // Montenegrin (Montenegro)
    "no":           ",", // Norwegian
    "no_NO":        ",", // Norwegian (Norway)
    "pl":           ",", // Polish
    "pl_PL":        ",", // Polish (Poland)
    "pt":           ",", // Portuguese
    "pt_AO":        ",", // Portuguese (Angola)
    "pt_BR":        ",", // Portuguese (Brazil)
    "pt_PT":        ",", // Portuguese (Portugal)
    "ro":           ",", // Romanian
    "ro_MD":        ",", // Romanian (Moldova)
    "ro_RO":        ",", // Romanian (Romania)
    "rm":           ".", // Romansh
    "rm_CH":        ".", // Romansh (Switzerland)
    "ru":           ",", // Russian
    "ru_RU":        ",", // Russian (Russia)
    "sr":           ",", // Serbian
    "sr_BA":        ",", // Serbian (Bosnia and Herzegovina)
    "sh":           ",", // Serbian (Latin)
    "sh_BA":        ",", // Serbian (Latin) (Bosnia and Herzegovina)
    "sh_CS":        ",", // Serbian (Latin) (Serbia and Montenegro)
    "sr_CS":        ",", // Serbian (Serbia and Montenegro)
    "sk":           ",", // Slovak
    "sk_SK":        ",", // Slovak (Slovakia)
    "sl":           ",", // Slovenian
    "sl_SI":        ",", // Slovenian (Slovenia)
    "es":           ",", // Spanish
    "es_AR":        ",", // Spanish (Argentina)
    "es_BO":        ",", // Spanish (Bolivia)
    "es_CL":        ",", // Spanish (Chile)
    "es_CO":        ",", // Spanish (Colombia)
    "es_CR":        ".", // Spanish (Costa Rica)
    "es_DO":        ".", // Spanish (Dominican Republic)
    "es_EC":        ",", // Spanish (Ecuador)
    "es_SV":        ".", // Spanish (El Salvador)
    "es_GT":        ".", // Spanish (Guatemala)
    "es_HN":        ".", // Spanish (Honduras)
    "es_MX":        ".", // Spanish (Mexico)
    "es_PA":        ".", // Spanish (Panama)
    "es_PY":        ",", // Spanish (Paraguay)
    "es_PE":        ",", // Spanish (Peru)
    "es_PR":        ".", // Spanish (Puerto Rico)
    "es_ES_EURO":   ",", // Spanish (Spain,Euro)
    "es_ES":        ",", // Spanish (Spain)
    "es_UY":        ",", // Spanish (Uruguay)
    "es_VE":        ",", // Spanish (Venezuela)
    "sv":           ",", // Swedish
    "sv_SE":        ",", // Swedish (Sweden)
    "tl":           ".", // Tagalog
    "tl_PH":        ".", // Tagalog (Philippines)
    "tg_TJ":        ".", // Tajik (Tajikistan)
    "th":           ".", // Thai
    "th_TH":        ".", // Thai (Thailand)
    "tr":           ",", // Turkish
    "tr_TR":        ",", // Turkish (Turkey)
    "uk":           ",", // Ukrainian
    "uk_UA":        ",", // Ukrainian (Ukraine)
    "ur":           ".", // Urdu
    "ur_PK":        ".", // Urdu (Pakistan)
    "vi":           ",", // Vietnamese
    "vi_VN":        ",", // Vietnamese (Vietnam)
    "cy":           ".", // Welsh
    "cy_GB":        "."  // Welsh (United Kingdom)
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .