0
我有浮動轉換爲字符串「錯誤」和浮動
total = quant * valUnit;
lb_total.setText(String.format(Locale.US,"%.2f", total));
if total = 56.025(7.5 * 7.47) > 56.02
if total = 71.025(7.5 * 9.47) > 71.03
爲什麼第一輪沒有一個代碼?
我找到了解決方案,我的問題,我創建一個類,使其正確。
import java.lang.Math;
// iniF = value to be rounded
// posIni = number of max houses(EX: 7.45 * 7.999, max houses for this operation is five)
// posFin = number of houses after rounded
// EX: xx*.xxxxx -> xx*.xx posIni = 5, posFin = 2
public class MyMath {
public Float MyRound(Float iniF, int posIni, int posFin){
Float result = 0.00f;
int resultTmp = 0;
int nCasas = (int) Math.pow(10, posIni - 1);
Float arredondaF = iniF * nCasas;
for(int p = posIni; p > posFin; p--){
resultTmp = Math.round(arredondaF);
arredondaF = (float) resultTmp/10;
}
result = arredondaF/10;
return result;
}
}