Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / November 2005

Tip: Looking for answers? Try searching our database.

rounding numbers

Thread view: 
ste1986 - 23 Nov 2005 21:22 GMT
how do i round decimal numbers?

iv tried Math.round.rental but it wont work. i think im doing it wrong!!!
Hal Rosser - 23 Nov 2005 21:43 GMT
> how do i round decimal numbers?
>
> iv tried Math.round.rental but it wont work. i think im doing it wrong!!!

TRY
long roundedResult = Math.round(rental)

Show us  the code.
Math.round(yourNumber) returns a long if yourNumber is a double - but
returns an int if yourNumber is a float.
If you're wanting to round to a certain number of places, there are several
approaches.
1.  Look at the NumberFormat class in the API -
OR
2. to round to 2 digits - multiply by 100 - then round to an int, then
divide by 100.
cbroussard@liquiddatainc.com - 26 Nov 2005 23:56 GMT
I'd also look at
http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigDecimal.html.

www.binaryfrost.com
Roedy Green - 23 Nov 2005 21:53 GMT
>how do i round decimal numbers?

To round a float or double, use Math.round or add .5 and convert to
int.

To round a BigDecmial use BigDecmial.round
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.