B4A Library Locale.jar

Semen Matusovskiy

Well-Known Member
Licensed User
Release 1.02.

Added function decimalFormat to support the class DecimalFormat ( https://developer.android.com/reference/java/text/DecimalFormat )

Examples:

smLocale.setFormatterLocale ("fra", "FRA")

Log (smLocale.decimalFormat ("#.##", 123456.789)) ' Output 123456,79
Log (smLocale.decimalFormat ("#", 123456.789)) ' Output 123457
Log (smLocale.decimalFormat ("###,###.##", 123456.789)) ' Output 123 456,79

If to use english locale ( smLocale.setFormatterLocale ("eng", "USA") ) the output will be

Log (smLocale.decimalFormat ("#.##", 123456.789)) ' Output 123456.79
Log (smLocale.decimalFormat ("#", 123456.789)) ' Output 123457
Log (smLocale.decimalFormat ("###,###.##", 123456.789)) ' Output 123,456.79


Release 1.01.

Added support for the class Formatter ( https://developer.android.com/reference/java/util/Formatter )

format - Returns a formatted string using the specified locale, format string, and arguments. Format string syntax is absolutelly the same as in Android documentation.
setFormatterLocale - changes a locale used for Format function

Example:
Dim smLocale As smLocale

smLocale.Format ("%9.2f", Array (12345.6)) will return 12345.60 for English language or 12345,60 for French.
smLocale.Format ("%tA", Array (DateTime.Now)) will return sexta-feira for Portugal or Friday for English.

Can be some arguments, that's why Array is used even in case, when the argument is alone.

Typically the application uses one language only, which you can set in Activity_Create. For example, smLocale.setLocale ("por", "BRA", False).
But if you want to use another language for Formatter, use setFormatterLocale before Format (for example, smLocale.setFormatterLocale ("deu", "DEU"))
 
Last edited:
Top