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;
}
}