首页 > 其他分享 >Double NaN

Double NaN

时间:2023-02-08 12:11:53浏览次数:48  
标签:java BigDecimal Double NaN base Test math

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Test {
    public static void main(String f[]) {

        Double dto = 1.0/0;
        Double vo = dto + 2.0;
        Double po = getPresicionScale(vo);
    }

    static Double getPresicionScale(Double actualValue)
    {
        Double value=0.0;
        if(actualValue!=null)
        {
            return  BigDecimal.valueOf(actualValue).setScale( 5, RoundingMode.DOWN).doubleValue();
        }
        return value;
    }
}

  

Exception in thread "main" java.lang.NumberFormatException: Character I is neither a decimal digit number, decimal point, nor "e" notation exponential mark.
at java.base/java.math.BigDecimal.<init>(BigDecimal.java:518)
at java.base/java.math.BigDecimal.<init>(BigDecimal.java:401)
at java.base/java.math.BigDecimal.<init>(BigDecimal.java:834)
at java.base/java.math.BigDecimal.valueOf(BigDecimal.java:1304)
at com.jds.test.httpproxy.miniserver.Test.getPresicionScale(Test.java:19)
at com.jds.test.httpproxy.miniserver.Test.main(Test.java:11)

 

報錯的堆棧奇特

public static BigDecimal valueOf(double val) {
// Reminder: a zero double returns '0.0', so we cannot fastpath
// to use the constant ZERO. This might be important enough to
// justify a factory approach, a cache, or a few private
// constants, later.
return new BigDecimal(Double.toString(val));
}

1

1/0 沒報錯

1/0+2 沒報錯

Double -> double 沒報錯

在BigDeciaml構造報錯

Double.isNaN isInfite 判斷

标签:java,BigDecimal,Double,NaN,base,Test,math
From: https://www.cnblogs.com/silyvin/p/17101273.html

相关文章