I have zero experience with formatting using a comma rather than a period when showing currency. For example ###,###.00 versus ###,###,00. It would appear to be a problem doing math with commas and from what I’ve read in Xojo Formatting the period may be the universal method of showing less than a whole value of say a dollar. Could someone kindly explain how monetary amounts are shown in Europe if the comma can be used in Xojo. Thank you.
Generally, there are at least five different formats where the decimal delimiter and thousand separators are represented by either a period, space or comma. With exceptions of course like no thousand separator (see Spanish) and typically the decimal delimiter is limited to the use of either a period or comma.
1,234.56 // English, Chinese, Japanese, etc.
1 234,56 // French, French-Canadian, Ukrainian, etc.
1234,56 // Spanish
1.234,56 // German, Italian, Icelandic, Romanian, etc.
١٫٢٣٤٫٥٦ // Arabic
The above is what should be displayed to the end-user depending on their Locale.Current using the toString method.
Likewise, if you’re allowing users to enter numbers and your app supports localization, you can capture these specially formatted numbers and convert them into programmable Doubles
using the .FromString method - because ultimately you want to store (and program) the values as Doubles
in the English format.
Are you looking for a specific language example?
There are 2 ways to format numbers with Xojo:
- Format
- ToString
ToString is available for:
Double.ToString format pattern is different that what old Format offers. It is based on the Unicode Number Format Pattern.
Currency.ToString allows to supply a locale, that way it formats and adds money symbol according to the locale, for example dollar sign to the left and comma separator but euro sign to the right and period or space for separator.
You may want to read about the available options, you may want to adopt Format or ToString depending on your needs.
It’s also worth mentioning, one of the less obvious things about the formatting codes, e.g., #,##0.00
, is that the comma and period are used to indicate where to place the thousand separator and decimal delimiter.
So, depending on the locale, the comma and period will be replaced in the output.
Var num As Double = 1234.56
num.ToString(New Locale("en-US"), "#,##0.00") // 1,234.56
num.ToString(New Locale("fr-FR"), "#,##0.00") // 1 234,56
num.ToString(New Locale("es-ES"), "#,##0.00") // 1234,56
num.ToString(New Locale("de-DE"), "#,##0.00") // 1.234,56
num.ToString(New Locale("ar-SA"), "#,##0.00") // ١٫٢٣٤٫٥٦
Scott and Alberto, thank you for your replies. This gives me a starting point for understanding how to go about this. Sometimes it’s difficult to location info when you don’t know what to look for.