The Java Runtime Environment is fully localized, and that capability can be used in Talend Open Studio jobs.
Java uses the Locale class to handle locale-specific data formats for currency, date, numbers, and messages. Locale is a combination of country and language that identifies a particular combination of formats for internationalization This blog post shows an internationalized handling of number formats.
In the U.S., decimal numbers use a dot for a decimal separator and a comma for a thousands separator.
Ex. 1,000.25007401
Other countries represent decimal numbers using the comma as a decimal separator and a dot for a thousands separator.
Ex. 1.000,25007401
There are other variations. A space could be used for a thousands separator. There may be no thousands separator.
To handle this in Talend Open Studio, a tMap can invoke Java parsing routines that are driven by a Locale. In this tMap example, two variables are declared 'usVar' and 'itVar' that are String constants of different number formats. The tMap will use the NumberFormat class to parse the numbers into a double.
From the input, a parse() method is called on a NumberFormat object. The NumberFormat is based on a Locale; many Locale constants are available: FRENCH, ITALY, SIMPLIFIED_CHINESE, UK. Read the Javadoc for the Locale class for a full listing. Sometimes, a country (FRANCE) and a language (FRENCH) seem to be redundant. Other times, this is more relevant (US/UK/ENGLISH).
The output schema is using a Double. If using a BigDecimal for additional precision or integration with other libraries, see the Talend Forum pagehttp://www.talendforge.org/forum/viewtopic.php?id=15502.
If these classes -- NumberFormat, Locale -- are used repeatedly, it's worthwhile to import the classes using a tJava. On the "Advanced settings" tab, put "import java.util.Locale" and "import java.text.NumberFormat" (no quotes). Then, the package of java.text.NumberFormat can be removed.
You can handle your internationalized data using Java's Locale class. This example converted String numbers in different formats to a common Java type (Double). Other uses of Locale include Date (month/day/year versus day/month/year), currency ($100 versus €100), or messages.
Java uses the Locale class to handle locale-specific data formats for currency, date, numbers, and messages. Locale is a combination of country and language that identifies a particular combination of formats for internationalization This blog post shows an internationalized handling of number formats.
In the U.S., decimal numbers use a dot for a decimal separator and a comma for a thousands separator.
Ex. 1,000.25007401
Other countries represent decimal numbers using the comma as a decimal separator and a dot for a thousands separator.
Ex. 1.000,25007401
There are other variations. A space could be used for a thousands separator. There may be no thousands separator.
To handle this in Talend Open Studio, a tMap can invoke Java parsing routines that are driven by a Locale. In this tMap example, two variables are declared 'usVar' and 'itVar' that are String constants of different number formats. The tMap will use the NumberFormat class to parse the numbers into a double.
Locale Used in a Talend tMap |
The output schema is using a Double. If using a BigDecimal for additional precision or integration with other libraries, see the Talend Forum pagehttp://www.talendforge.org/forum/viewtopic.php?id=15502.
If these classes -- NumberFormat, Locale -- are used repeatedly, it's worthwhile to import the classes using a tJava. On the "Advanced settings" tab, put "import java.util.Locale" and "import java.text.NumberFormat" (no quotes). Then, the package of java.text.NumberFormat can be removed.
You can handle your internationalized data using Java's Locale class. This example converted String numbers in different formats to a common Java type (Double). Other uses of Locale include Date (month/day/year versus day/month/year), currency ($100 versus €100), or messages.
Comments
Post a Comment