Why not working printf on Java in the app? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why not working printf on Java in the app?

Example: System.out.printf("Float number is " + "%.2f");

11th Jul 2017, 9:05 PM
Ferhat Sevim
Ferhat Sevim - avatar
7 Answers
+ 1
Not sure why printf wouldn't be working. However, I know String.format will work on code playground. Example/ System.out.println(String.format("%.2f", nbr*pi)); Little more to write though 😖 Edit: Actually, doing the same thing with printf worked fine for me: https://code.sololearn.com/ch84ZHUS7C7F/?ref=app
11th Jul 2017, 10:07 PM
Rrestoring faith
Rrestoring faith - avatar
0
have you tried System.out.println(); or just System.out.print();
11th Jul 2017, 9:17 PM
D_Stark
D_Stark - avatar
0
Yes, I have tried it and then it will print out like text not make number shorter.
11th Jul 2017, 9:19 PM
Ferhat Sevim
Ferhat Sevim - avatar
0
im assuming theres more code becuase here your just printing your text using " " usually there should be variables
11th Jul 2017, 9:27 PM
D_Stark
D_Stark - avatar
0
https://code.sololearn.com/cM9lxn7En339/?ref=app Here I am trying I want the printed number will be with 2 decimals. If you try at eclipse, it is working well.
11th Jul 2017, 9:39 PM
Ferhat Sevim
Ferhat Sevim - avatar
0
sorry i think i may be out my depth here as i havent covered pi,math or irational numbers with java. i know that irrational numbers can go on forever without repeating so im unsure if that could be the problem.... :/ i hope somone can help you
11th Jul 2017, 10:07 PM
D_Stark
D_Stark - avatar
0
Yes, I have noticed it in printf. it was using comma. Thanks for helping.
11th Jul 2017, 10:54 PM
Ferhat Sevim
Ferhat Sevim - avatar