Rounding a currency value to the nearest dollar

Posted on 2005-04-28
Last Modified: 2011-10-03
I want to know how to take a double, which I am currently formatting with NumberFormat using the format() method to make into currency, and chop off the cents by rounding up to the nearest whole number.  I tried a Math.round() on the double, but it still displays something like $123.00 instead of $123.  How can you take a double, round it up, and convert it into a currency format?

Question by:gdlp2004
    LVL 86

    Expert Comment

    Quick and dirty:

                NumberFormat nf = new DecimalFormat("0");
                      double d = 123.123;
    LVL 86

    Accepted Solution


                      nf = NumberFormat.getCurrencyInstance();
    LVL 86

    Expert Comment

    If you want dollars irrespective of Locale:

    nf = NumberFormat.getCurrencyInstance(Locale.US);

    Author Comment

    Thanks man, you rock. :)
    LVL 86

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    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…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now