溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

java.text.DecimalFormat

發(fā)布時間:2020-07-18 10:07:23 來源:網(wǎng)絡 閱讀:359 作者:101ttyy 欄目:開發(fā)技術(shù)

DecimalFormat 在 java.text 包里

對數(shù)字進行轉(zhuǎn)換的類

public static void main(String[] args) {
        String feeStr ="2145";//以分為單位
        DecimalFormat df1 = new DecimalFormat("##.##");
        String fee1 = df1.format((Double.parseDouble(feeStr) / 100));
        DecimalFormat df2 = new DecimalFormat("0.00");
        String fee2 = df2.format((Double.parseDouble(feeStr) / 100));
        DecimalFormat df3 = new DecimalFormat(".##");
        String fee3 = df3.format((Double.parseDouble(feeStr) / 100));
        System.out.println("fee1="+fee1+",fee2="+fee2+",fee3="+fee3);
    }


結(jié)果:

fee1=21.45
fee2=21.45
fee3=21.45


向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI