第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

減去 bigDecimal 數(shù)字會(huì)產(chǎn)生 0 的精度?

減去 bigDecimal 數(shù)字會(huì)產(chǎn)生 0 的精度?

慕的地8271018 2022-10-07 16:32:16
我正在減去兩個(gè) bigDecimal 數(shù)字。進(jìn)入減法方法,它們都具有非零精度,但結(jié)果精度= 0。據(jù)我所知,精度為 0 的 bigDecimal 數(shù)是不可能的。即使 0 的精度為 1。精度是未縮放值中的位數(shù)。例如,對(duì)于數(shù)字 123.45,返回的精度為 5。(另見(jiàn)BigDecimal、precision 和 scale)。有問(wèn)題的區(qū)域:BigDecimal test = (centerHP.getReal().subtract(inverseScale));centerHP.getReal()返回從該行創(chuàng)建的bigDecimalnew BigDecimal(Double.toString(center.getReal()))對(duì)于上下文center.real = -0.79,它是雙精度的。所以它是有效的new BigDecimal("-0.79")inverseScale 只是 1double scale = 1;BigDecimal inverseScale = (BigDecimal.ONE.divide(new BigDecimal(Double.toString(scale))));我希望 test 是一個(gè)值為 -1.79 的 bigDecimal,int 表示應(yīng)該是 -179,精度為 3,小數(shù)位數(shù)為 2。但是,緊隨 BigDecimal 類(lèi)中減法方法中的加法運(yùn)算之后,我的值如下:和測(cè)試等于:請(qǐng)注意,所有其他值都是正確的,只是精度似乎是錯(cuò)誤的。
查看完整描述

1 回答

?
呼如林

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超3個(gè)贊

從該字段的 javadoc 中,0意味著精度未知。


/**

 * The number of decimal digits in this BigDecimal, or 0 if the

 * number of digits are not known (lookaside information).  If

 * nonzero, the value is guaranteed correct.  Use the precision()

 * method to obtain and set the value if it might be 0.  This

 * field is mutable until set nonzero.

 *

 * @since  1.5

 */

private transient int precision;

該方法precision()懶惰地確定精度。


public int precision() {

    int result = precision;

    if (result == 0) {

        long s = intCompact;

        if (s != INFLATED)

            result = longDigitLength(s);

        else

            result = bigDigitLength(inflate());

        precision = result;

    }

    return result;

}


查看完整回答
反對(duì) 回復(fù) 2022-10-07
  • 1 回答
  • 0 關(guān)注
  • 172 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)