int value1 = 123456789;
float value2 = value1;
System.out.println(value1);
System.out.println(value2);
Run Code Online (Sandbox Code Playgroud)
输出:
123456789
123456792
在循环中,我添加0.10,直到达到所需的#,并获得索引.这是我的代码:
private static int getIndexOfUnits(float units) {
int index = -1;
float addup = 0.10f;
for(float i = 1.00f; i < units; i=(float)i+addup) {
index++;
System.out.println("I = " + i + " Index = " + index);
}
return index;
}
Run Code Online (Sandbox Code Playgroud)
如果通过的单位是5.7,我看到的输出是:
I = 1.0 Index = 0
I = 1.1 Index = 1
I = 1.2 Index = 2
I = 1.3000001 Index = 3
I = 1.4000001 Index = 4
I = 1.5000001 Index = 5
I = …Run Code Online (Sandbox Code Playgroud)