Win a copy of Head First Agile this week in the Agile forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

Round the float number?

Elahe Shafie
Ranch Hand
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
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
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