You find very good articles about number formats and date formats on Wikipedia:
https://en.wikipedia.org/wiki/Decimal_separator
https://en.wikipedia.org/wiki/Calendar_date#Date_format
In many countries (including Germany) the decimal separator is a comma, the thousands separator is a point. But in Switzerland the decimal separator is a point, the thousands separator is a high comma (apostrophe). The formats for dates vary as everyone knows.
In LiveCode, when working for international clients, you need to think about how to handle such different format since they are what I call "presentation layer". The storage layer in LiveCode could be a custom property, an array, a SQLite database or a text file. So, presenting dates, times and decimal numbers is different from the storage.
Instead of putting something into a field, you might set a custom property:
Code: Select all
--- Example:
set the uValue of field "myThousands" to 1000000"
put convertNumber(the uValue of field "myThousands") into field "myThousands"
The resulting formatted number may look like "10,000,000.00" or like "10.000.000,00" or like "10 000 000.00" or like "10'000'000.00" depending on the lokale value the user sets or the system default settings.
So, on
closeField or
changeText or similar messages, formatted data will also be changed on the storage level.
To automate this, you can use
setProp and
getProp handlers that will automatically convert a changed or entered value in both directions and present the desired format according to chosen locale.
Of course, there are also disadvantages using such method. Ideally, the presentation layer is so closely and automatically bound to the stored value that I would even favor a special field property to define the presentation and the storage and the field will take care of the binding itself (see this in Filemaker). The presented formatted value may not even have to be stored at all and is always an unstored calculated value. But I would not know how to do this in LiveCode as fields always store data put in. Or not?
Problems appear when importing other sets of formatted numbers since it is not always possible to know in advance which format such imported numbers (or dates) have. In some countries you cannot even be sure that the fractional part of the number is not also formatted leaving number formats to become a wild guess.
In my opinion, it would be DEVELOPER FRIENDLY if such functions for the formatting of dates and times as well as decimal numbers would be engine functions covering all defined international locales. In Excel and all other kinds of applications we do not need to write functions (usually), but just define the type to be used. It is just an overhead for us now.
I very much hope to once see the international date format supported by the engine: YYYY-MM-DD HH:MM:SS. It should be simple to use and convert to date items, other date formats, etc. It is used in databases.