The following code:
DecimalFormat df = new DecimalFormat();
df.setMinimumFractionDigits(2);
int zahl1 = 10;
int zahl2 = 18;
double double1 = zahl1 / zahl2;
System.out.println("Double1 = " + df.format(double1));
double double2 = Math.ceil(zahl1 / zahl2);
System.out.println("Double2 = " + df.format(double2));
double double3 = Math.round((zahl1 / zahl2) * 100) / 100;
System.out.println("Double3 = " + df.format(double3));
float float1 = Math.round((zahl1 / zahl2) * 100) / 100;
System.out.println("Float1 = " + df.format(float1));
long long1 = zahl1 / zahl2;
System.out.println("long1 = " + df.format(long1));
long long3 = Math.round((zahl1 / zahl2) * 100) / 100;
System.out.println("long3 = " + df.format(long3));
产出如下:
Double1 = 0,00
Double2 = 0,00
Double3 = 0,00
Float1 = 0,00
long1 = 0,00
long3 = 0,00
我现在对浮标和双倍以及 Java不怎么说,但我似乎并不完全理解如何达到我所期望的结果0.6。
我做了什么错误?