Java and Currency Counting (Brazil)

Posted on 2011-03-09
Last Modified: 2012-05-11
Hi Experts,

I'm trying to format currency in Brazil but Java simply does not know how to handle this.

NumberFormat format = NumberFormat.getInstance(new Locale("br"));
Object value = format.parse("5,45");

value ends up translating to 54500.  It's very strange.  Does anyone know why and how I can properly format the value?

Question by:Greengiants15
  • 2
  • 2
LVL 92

Expert Comment

ID: 35090616
LVL 92

Expert Comment

ID: 35090630
and you should be use getCurrencyInstance() to parse a currency value
LVL 86

Accepted Solution

CEHJ earned 500 total points
ID: 35093013
You're constructing your Locale wrongly. Should be
new Locale("pt", "BR")

Open in new window

LVL 86

Expert Comment

ID: 35095023

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Should localization be done inside spring controller 5 32
tomcat administrtor 12 61
ejb wildfly example 2 27
American Express @Work site and Java 4 30
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question