This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Quick question" Watch "Quick question" New topic

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.


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

Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: Quick question
jQuery in Action, 3rd edition