Numbers to Strings with custom symbols // DecimalFormat – DecimalFormatSymbols


When printing reports or casting Strings to Numbers, it’s very useful to use the DecimalFormat class found in java.text. This class is pretty straightforward and easy to use, but some problems may be found when your work with this class in computers from other countries. Internationalization will cause your program to behave in a way you may not expect in some cases.

If you use this class to parse a number to a String, you may find that when a user enters a number in a french computer you will be getting a ParseException, because the computer is expecting different symbols. Here is where the DecimalFormatSymbols class becomes very useful.

With the following code I’ll show you how easy is to change the symbols and make them independent of different Locales.

Tweet about this on TwitterShare on FacebookShare on LinkedInShare on Google+Pin on PinterestEmail this to someone

Leave a comment

Your email address will not be published. Required fields are marked *