Java number of decimals | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Java number of decimals

Hello! If I have a double: double number = 35.2; And I need to convert it to 35.20 then how do I do that?

19th Nov 2020, 2:38 PM
Michał Cukrowski
Michał Cukrowski - avatar
3 Answers
+ 1
double d = 35.2; System.out.printf("%.2f",d);
19th Nov 2020, 3:10 PM
Avinesh
Avinesh - avatar
0
I don't need to just print it but to change its value so that it remains 'number' variable it already is
19th Nov 2020, 3:32 PM
Michał Cukrowski
Michał Cukrowski - avatar
0
Michał Cukrowski any reason why you want to change it to 35.20? Cuz 35.2 is the exact same thing as 35.20. so there's no need to change it, unless you want to print it in 35.20 format then do what Avinesh said.
19th Nov 2020, 5:47 PM
pNK
pNK - avatar