+ 1

Java. Decimal spaces %.3f

Hi! I'm trying to display the average number with 3 decimal spaces using %.3f. Problem is, that numbers go through the "," instead of dot, which is not correct. To make it short: double n = 7; double z = 8; avg = (n+z)/2; System.out.printf("The average of entered numbers is: %.3f", avg); Output: The average of entered numbers is: 7,500 (Should be 7.500) Any help is much appreciated!

4th Jun 2018, 6:33 PM
DIY Mods
DIY Mods - avatar
2 Réponses
+ 1
I just managed to do it with a java.util.Locale, but why? I never had this issue before. Just updated to Eclipse Neon 3 and begun to have multiple issues and this is the one. Is there any way to fix it, so I don't need to import Locale? Thanks!
4th Jun 2018, 7:10 PM
DIY Mods
DIY Mods - avatar
+ 1
try using DecimalFormat class otherwise replace the comma with a dot via the string.replace() function.
4th Jun 2018, 8:38 PM
Duccio Bertieri
Duccio Bertieri - avatar