public class Main {
public static void main(String[] args) {
int a = 10;
int b = 100;
double c = (double) (a/b);
String str = String.format("%1.4f", c);
System.out.println(str);
}
}
In this case, the result of dividing 2 integers will also be casted to an integer (0) and only after it casted to double (0.0). %1.4f prints a floating point number with precisions of 4 digits after dot.
To bring 0.1000 on the console it is necessary to change the line double c = (double) (a / b) to the double c = (double) a/b .
Ввійдіть щоб вподобати
Ввійдіть щоб прокоментувати