rounding numberformat

Discussion in 'Java' started by Joe Pribele, Aug 19, 2003.

  1. Joe Pribele

    Joe Pribele Guest

    Can some please explain to me this whole odd even rounding in java ?

    Why does 1.445 not round up to 1.45 ?
    I did come across in the java docs something out odd and even neighbours
    but it didn't make much sense to me.

    public class test {

    public static void main(String[] args ) {
    System.out.println( java.text.NumberFormat.getCurrencyInstance
    ().format( 1.445 ) );
    }
    }
     
    Joe Pribele, Aug 19, 2003
    #1
    1. Advertising

  2. Joe Pribele

    Roedy Green Guest

    On Tue, 19 Aug 2003 17:35:41 GMT, Joe Pribele
    <jpribele@no_spam.bglgroup.com> wrote or quoted :

    > System.out.println( java.text.NumberFormat.getCurrencyInstance
    >().format( 1.445 ) );


    You can always specify your own mask. See
    http://mindprod.com/converter.html double to String.

    It might be informative to print out all the trivia you can about the
    object getCurrencyInstance is returning you. Perhaps it thinks 3
    decimal places in just fine for some exotic currency you got by
    mistake.

    If it is suggesting 3 places for US dollars, this deserves a slot in
    the gotchas page at http://mindprod.com/jgloss/gotchas.html

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Aug 19, 2003
    #2
    1. Advertising

  3. Joe Pribele

    Frank Guest

    On Tue, 19 Aug 2003 17:35:41 GMT, Joe Pribele
    <jpribele@no_spam.bglgroup.com> wrote:

    > Can some please explain to me this whole odd even rounding in java ?
    >
    > Why does 1.445 not round up to 1.45 ?
    > I did come across in the java docs something out odd and even neighbours
    > but it didn't make much sense to me.
    >
    > public class test {
    >
    > public static void main(String[] args ) {
    > System.out.println( java.text.NumberFormat.getCurrencyInstance
    > ().format( 1.445 ) );
    > }
    > }
    >


    Aiehhhhh, the Office Space virus lives on!






    (Yes I'm aware it was implemented in practice well before the movie)
     
    Frank, Aug 20, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kiran
    Replies:
    2
    Views:
    5,207
    kiran
    Nov 2, 2005
  2. HEP
    Replies:
    1
    Views:
    629
  3. mtp
    Replies:
    2
    Views:
    401
  4. Scott Smith
    Replies:
    4
    Views:
    1,208
  5. StephaneLeFou

    NumberFormat vs double and long

    StephaneLeFou, Jun 11, 2008, in forum: Java
    Replies:
    4
    Views:
    423
    StephaneLeFou
    Jun 12, 2008
Loading...

Share This Page