*
The moose likes JDBC and the fly likes Round the float number? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Round the float number?" Watch "Round the float number?" New topic
Author

Round the float number?

Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
Hi friends,
Could you please tell me how can I round the number between 0 and 1
I have a table here and when I run the query it just return 0 and doesn't round the numbers for me!!
Thanks a lot for your help,
Elahe
My query
==========
SELECT Round( tPoints.coef2)
FROM tPoints;
tpoints table
=============
Coef2
----------
9.7765472E-07
1.5250309E-06
1.5173E-06
9.7765472E-07
1.5173E-06
1.5173E-06
1.5173E-06
9.67765472E-07
1.1712652E-06
1.5173E-06
1.5234311E-06
Jeff Grant
Ranch Hand

Joined: Dec 19, 2001
Posts: 169
Originally posted by elahe shafie:
9.7765472E-07
1.5250309E-06
1.5173E-06
9.7765472E-07
1.5173E-06
1.5173E-06
1.5173E-06
9.67765472E-07
1.1712652E-06
1.5173E-06
1.5234311E-06

Is my math bad or doesn't "E-06" mean the decimal goes left 6? If so... 1.5173E-06 = 0.0000015173 which is rounded to 0... perhaps?
Perhaps, actually, you are thinking of 1.5173E-06 as being 1.5173? Then that'd round to 2... but the E-06 is part of the number which Java won't ignore. If the 1.5173 = 2 idea is right, then you could write a nice little function to do it for you... but that'd be a pain.
Oh well, hope I just let you know what math with E-06 really means... or I hope that someone lets me know so I don't forget this time, but I probably will if I'm wrong!
[ October 19, 2002: Message edited by: Jeff Grant ]
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

You can use java.lang.Math's "public static long round( double d )" for simple rounding or for more rounding options see java.Math.BigDecimal for different rounding options.
Jamie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Round the float number?
 
Similar Threads
Query question
swing component exception
Query problem with MySQL 5
Transforming a table
duplicate created in AUTO INCREMENT in mysql if its possible?