+ 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!
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!
+ 1
try using DecimalFormat class otherwise replace the comma with a dot via the string.replace() function.