0

How can we give precision to the decimal numbers (float)

30th Jul 2016, 12:29 PM
Melvin Vijay
Melvin Vijay - avatar
4 odpowiedzi
+ 3
System.out.printf("%.xf", number); Replace x with the number of decimal places you want
30th Jul 2016, 5:29 PM
Vamsi Manepalli
Vamsi Manepalli - avatar
+ 1
Use Double instead of float it gives you more precision other than float.
31st Jul 2016, 5:26 AM
Anand Kumar
Anand Kumar - avatar
+ 1
If double has not enough precision, use BigDecimal. This data type isn't primitive. Its an object similar to the wrapper classes (Integer,Character...), so you need to use methods instead of operators. It could help to read the documentation
31st Jul 2016, 6:12 AM
No One
No One - avatar
0
float default precision is 6
11th Aug 2016, 6:14 PM
srilekha