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 page http://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.
Hello Carl,
ReplyDeleteOnce again, excellent post on Talend Open Studio.
Thanks a lot,
Talend Community Manager.
your post enabled me to solve my actual number formatting problem in talend, thanks carl from alois
ReplyDeleteGlad to have helped alois. -Carl
ReplyDeletewanted to receive an email, Hi Carl, how would you place the thousands comma in the double?
ReplyDeleteYour article is too good and informative. Keep writing and sharing educational article like this which can help us to grow our knowledge.
ReplyDeleteJAVA Training In Pune
Thanks for sharing with us. I just loved your way of presentation. I enjoyed reading this .Thanks for sharing and keep writing. It is good to read blogs like this.
ReplyDeleteRubix Research
This is very usefull blog, keep sharing. Thanks!
ReplyDeleteJava Classes in Pune
Wow what an article please keep sharing such content.
ReplyDeleteJava Classes in Pune
One of the best things i came across on the internet. Thanks for sharing.
ReplyDeleteWeb Development Classes in Pune
Android Classes in Pune
Web Design Classes in Pune
Hi for big Decimal what will be the formula ? thanks
ReplyDeletenice post, Java Training Course In Amravati
ReplyDelete