Created on 11 January 2021
icon_unfollowing
Login to follow
format-currency

Format Currency

Stable version 1.0.5 (Compatible with OutSystems 11)
Uploaded on 25 January 2021 by 
format-currency

Format Currency

Documentation
1.0.5

Available Actions


The action GetCurrencyFormattedByLocale formats a decimal with the following parameters:

  • Locale: the RFC 4646 representation of the locale as provided by the GetLocales, eg: "en-GB" for Pounds in the United Kingdom Culture;
  • Decimal: the provided decimal;
  • HasCurrency: if the number will have the currency symbol;
  • Currency: if "" then uses the default currency for that locale, if not empty, uses what is passed here;
  • UseNativeDigits: if the digits 0-9 are formatted using the native digits or the 0-9;
  • UseChineseExtendedNumbers: If the locale starts with "zh", and this is true, the native numbers will be using the chinese unit system instead of the arabic or partial chinese numbers;
  • UseFinancialChinese: If the locale starts with "zh", and this is true, it will use financial chinese numeration example:  零 "líng" instead of 〇, normally in financial applications 零 is used to avoid fraud;
  • FormattedText: the resulting text;

UseFinancialChinese and UseChineseExtendedNumbers will only have noticeable changes within the "zh" locales, putting them True, only will change the digits if within the "zh" locales.


The action GetDecimalFromLocaleDecimalString converts a Locale Decimal String (a decimal that was written in in a certain locale) into a valid Decimal. For now "zh" locale that uses the extended numbers and financial numbers will give the 3 - "Format Exception".

  • InputLocalelDecimalString:The String containing the Locale Decimal to convert into Decimal
  • Locale: The Locale that the string was written on. (It will try both native and 0-9 numbers from the locale).
  • IsValidDecimal: If the converted Decimal is a valid one, if not then the Error Message will have the reason that the conversion failed.
  • ErrorMessageCode: The code of the Error Message.
  • ErrorMessage: Error Message in case the converted Decimal is not valid.
  • Decimal: The Decimal converted, if the IsValidDecimal is notTrue, then this will be the default value 0.0;


Error Message Codes and meanings:

  • 0 - "" - No Error
  • 1 - "String Empty" - The string was empty
  • 2 - "Locale Invalid/Not Provided" - No Locale was found
  • 3 - "FormatException [x]" - an error in the format of the number - log represented in x
  • 4 - "Other Errors [x]" - other errors - log represented in x



The action GetLocales provides a list of all the locales present in C# in the System.Globalization namespace in the CultureInfo and NumberFormatInfo classes, with some information about them:

  • Name: name of the locale;
  • RFC4646: the locale code;
  • CurrencyDecimalDigits: the number of decimal digits;
  • CurrencyDecimalSeparator: the separator of the decimal and whole number parts;
  • CurrencyGroupSeparator: the separator of the groups;
  • CurrencyGroupSizes: the sizes of the groups normally [3] or [3,2] for groups of three, and three for the whole numbers and two for the decimals;
  • CurrencyNegativePattern: the negative pattern for currency, may not have the negative symbol;
  • CurrencyPositivePattern: the positive pattern for currency;
  • NegativeSign: the negative sign, normally "-" but some locales don't use the negative symbol;
  • CurrencySymbol: the symbol of the currency;
  • NativeDigits: the native digits from 0-9;


Sample/Demo Screens


In the Sample/Demo you have two screens to help you use the actions:

  • SingleFormatCurrency: for testing the GetCurrencyFormattedByLocale;
  • FormatCurrency: seeing the GetLocales and corresponding formattings with GetCurrencyFormattedByLocale;
  • ConvertInputToDecimal: for testing the GetDecimalFromLocaleDecimalString;


Example Use Cases


You want to format 100.30 into the ฿ (Thai baht) currency (both native and not native):

  1. (optional if you have already the locale you need) Filter GetLocales with CurrencySymbol="฿", to get "th", "th-TH" in the RFC4646 attribute;
  2. Use the Locale in the GetCurrencyFormattedByLocale with the decimal:
    1. Locale:"th" or "th-TH";
    2. Decimal: 100.30;
    3. HasCurrency: in this we want the currency symbol, True;
    4. Currency: we don't need to change the currency symbol, "";
    5. UseNativeDigits:  True(if using native)/False(if not using native);
    6. UseChineseExtendedNumbers and UseFinancialChinese: aren't needed, False;
  3. FormattedText: ฿๑๐๐.๓๐ / ฿100.30

You want to format 100.30 into the £ (pound) currency but want the people in the Arabic countries to read it in the native format with the pound currency:

  1. Locale: The Arabic native digits are "٠,١,٢,٣,٤,٥,٦,٧,٨,٩ ", we can use the "ar" locale that has them as native digits and is general for Arabic Culture;
  2. Decimal: 100.30;
  3. HasCurrency: True;
  4. Currency: The currency is "£" to override the "ر.س" currency; 
  5. UseNativeDigits:True;
  6. UseChineseExtendedNumbers and UseFinancialChinese: aren't needed, False;
  7. FormattedText: "١٠٠.٣٠ £" ; 



Support options
This asset is not supported by OutSystems. You may use the discussion forums to leave suggestions or obtain best-effort support from the community, including from  who created this asset.
Dependencies
Format Currency has no dependencies.