Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > rounding numberformat

Reply
Thread Tools

rounding numberformat

 
 
Joe Pribele
Guest
Posts: n/a
 
      08-19-2003
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 ) );
}
}
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      08-19-2003
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.
 
Reply With Quote
 
 
 
 
Frank
Guest
Posts: n/a
 
      08-20-2003
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)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
NumberFormat vs double and long StephaneLeFou Java 4 06-12-2008 11:02 AM
Where are the resources used by NumberFormat? Scott Smith Java 4 03-01-2007 07:36 AM
Case sensitiveness in NumberFormat ? mtp Java 2 06-14-2006 10:26 AM
From NumberFormat to string pattern HEP Java 1 03-01-2006 01:22 PM
How to get "$ ###,###,##0.00" from CultureInfo.NumberFormat kiran ASP .Net 2 11-02-2005 05:37 PM



Advertisments