• BigDecimal 实际测试结果


    package com.zzzy;
    
    import java.math.BigDecimal;
    
    public class Test {
    
            public static void main(String[] args) {
                BigDecimal hundred = new BigDecimal(100);
                
                BigDecimal bd1 = new BigDecimal(1);
                BigDecimal bd2 = new BigDecimal("2");
                BigDecimal bd3 = new BigDecimal("3.0");
                BigDecimal bd4 = new BigDecimal("4.00");
                BigDecimal bd5 = new BigDecimal("05.0");
                BigDecimal bd6 = new BigDecimal("6.005");
                BigDecimal bd7 = new BigDecimal(6.005);
                
                System.out.println(bd1);
                System.out.println(bd2);
                System.out.println(bd3);
                System.out.println(bd4);
                System.out.println(bd5);
                System.out.println(bd6);
                System.out.println(bd7);
                
                System.out.println("-----------------------");
                
                System.out.println(bd7.compareTo(bd6));
                
                System.out.println("-----------------------");
                
                System.out.println(bd1.multiply(hundred));
                System.out.println(bd2.multiply(hundred));
                System.out.println(bd3.multiply(hundred));
                System.out.println(bd4.multiply(hundred));
                System.out.println(bd5.multiply(hundred));
                System.out.println(bd6.multiply(hundred));
                System.out.println(bd7.multiply(hundred));
                
            }
    }

    输出结果:

    1
    2
    3.0
    4.00
    5.0
    6.005
    6.00499999999999989341858963598497211933135986328125
    -----------------------
    -1
    -----------------------
    100
    200
    300.0
    400.00
    500.0
    600.500
    600.49999999999998934185896359849721193313598632812500
  • 相关阅读:
    CVS 快速入门指南
    我的博客皮肤
    OOP三个基本特征
    vi 操作
    智者能堪破这世界的定数,但没人能逃脱劫数
    技术路径的四阶段
    python每日学习2018/1/14(python之禅)
    python每日学习2018/1/11
    Python PyInstaller安装和使用教程(详解版)
    Windows环境下安装MinGW/gcc
  • 原文地址:https://www.cnblogs.com/ziwuxian/p/10338076.html
Copyright © 2020-2023  润新知