如何在 java 中使用 Math.round() 获取 =ROUND(A8/1000,2)* 1000 (excel 公式) 输出
how to use Math.round() in java for getting =ROUND(A8/1000,2)* 1000 (excel formula) output
我有一个值 7075.5
我需要将输出设为 7080
。我需要应用以下 Excel 公式来获得此输出。
=ROUND(A8/1000, 2) * 1000
如何使用 java 完成此 formula/requirement?
我尝试了很少,但我离预期的输出还很远。
public class Split {
public static void main(String[] args) {
double e = 7075.9;
System.out.println("Rounding 7075.5="+Math.round(e*1000)/1000);
}
}
有人可以帮忙在 Java 完成这项工作吗?请参考上面给出的excel公式。
当您只想四舍五入最后一位数字时,为什么要除以 1000
?
您可以使用
System.out.println("Rounding 7075.5="+Math.round(e/10)*10);
你在 excel 中使用 1000 进行除法和乘法很好,因为你可以为小数点后的数字传递额外的参数。
您甚至可以在 excel
中使用 foll
=ROUND(A8/10,0)*10
对于Java
Math.round(e/10)*10
我有一个值 7075.5
我需要将输出设为 7080
。我需要应用以下 Excel 公式来获得此输出。
=ROUND(A8/1000, 2) * 1000
如何使用 java 完成此 formula/requirement? 我尝试了很少,但我离预期的输出还很远。
public class Split {
public static void main(String[] args) {
double e = 7075.9;
System.out.println("Rounding 7075.5="+Math.round(e*1000)/1000);
}
}
有人可以帮忙在 Java 完成这项工作吗?请参考上面给出的excel公式。
当您只想四舍五入最后一位数字时,为什么要除以 1000
?
您可以使用
System.out.println("Rounding 7075.5="+Math.round(e/10)*10);
你在 excel 中使用 1000 进行除法和乘法很好,因为你可以为小数点后的数字传递额外的参数。
您甚至可以在 excel
中使用 foll=ROUND(A8/10,0)*10
对于Java
Math.round(e/10)*10