| Author |
Java (Precision Problem)
|
Pulkit Malhotra
Ranch Hand
Joined: Apr 15, 2005
Posts: 30
|
|
Hi , I'm having a float variable which displays value as 12.3333333333 i want it to show only upto 2 decimal places like 12.33. Can you please tell me is there any direct function for this in math or util package ? Thanks in advance.
|
Regards,<br />Pul_Mal
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
|
You'll find interesting things in the BigDecimal class.
|
[My Blog]
All roads lead to JavaRanch
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12924
|
|
So you want to format a number to show only 2 decimal places. You could do that like this: Or you could use java.text.DecimalFormat: [ May 25, 2007: Message edited by: Jesper Young ]
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: Java (Precision Problem)
|
|
|