File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Quick question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Quick question" Watch "Quick question" New topic
Author

Quick question

joew weakers
Ranch Hand

Joined: Aug 21, 2003
Posts: 48
Hi there. This is a really quick one. If I have a float value 3.5711762E-6,
how do I just return the number to four decimal places, i.e. 3.5718. Cheers, Joe
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
Probably have to convert it to a string and then use subString to get the right number of digits. If you were to use BigDecimal I think it has methods that do that for you.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
It depends on how you want to use the rounded version. If you are simply displaying the value, then you should use the NumerFormat class. If you need to round a number for calculations, you should look at the round() method in the Math class.

HTH

Layne
[ February 28, 2005: Message edited by: Layne Lund ]

Java API Documentation
The Java Tutorial
 
Don't get me started about those stupid light bulbs.
 
subject: Quick question