Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在java中使用Math.round()获取=round(A8/1000,2)*1000(excel公式)输出_Java_Math_Excel Formula_Rounding - Fatal编程技术网

如何在java中使用Math.round()获取=round(A8/1000,2)*1000(excel公式)输出

如何在java中使用Math.round()获取=round(A8/1000,2)*1000(excel公式)输出,java,math,excel-formula,rounding,Java,Math,Excel Formula,Rounding,我有一个值7075.5我需要将输出作为7080。我需要应用下面的Excel公式来获得此输出 =ROUND(A8/1000, 2) * 1000 如何使用java实现这个公式/需求? 我尝试了几次,但我离预期的结果很远 public class Split { public static void main(String[] args) { double e = 7075.9; System.out.println("Rounding 7075.5="+M

我有一个值
7075.5
我需要将输出作为
7080
。我需要应用下面的Excel公式来获得此输出

=ROUND(A8/1000, 2) * 1000
如何使用java实现这个公式/需求? 我尝试了几次,但我离预期的结果很远

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

为什么你只想把最后一个数字四舍五入,却要除以
1000

你可以用

System.out.println("Rounding 7075.5="+Math.round(e/10)*10);

在excel中使用1000进行除法和乘法很好,因为在excel中,您可以为小数点后的数字传递额外的参数

你甚至可以在excel中使用foll

=ROUND(A8/10,0)*10
对于Java

 Math.round(e/10)*10

在excel中使用1000进行除法和乘法很好,因为在excel中,您可以为小数点后的数字传递额外的参数

你甚至可以在excel中使用foll

=ROUND(A8/10,0)*10
对于Java

 Math.round(e/10)*10