rounding numberformat

J

Joe Pribele

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 ) );
}
}
 
R

Roedy Green

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
 
F

Frank

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)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top