BigDecimal与Long、int之间的互换

2019-10-15 17:08:47

在实际开发过程中BigDecimal是一个经常用到的数据类型,它和int Long之间可以相互转换。

转换关系如下代码展示:

int 转换成 BigDecimal 数据类型

  //int  转换成  bigDecimal类型
    public static void intToBigDecimal(){        int b = 5;
        BigDecimal a = new BigDecimal(b);
        System.out.println(a +"的数据类型是"+a.getClass().getName());
    }

Lont 转换成 BigDecimal 数据类型

  //Long 类型转换成 bigDecimal
    public static void longToBigDecimal(){        long b = 5;
        BigDecimal a = new BigDecimal(b);
        System.out.println(a +"的数据类型是"+a.getClass().getName());
    }

BigDecimal 转换成 Long数据类型

  //bigDecimal  转换成  Long类型
    public static void bigDecimalToLong(){
        BigDecimal b = new BigDecimal(12);
        Long c = b.longValue();
        System.out.println(c+"的数据类型是"+c.getClass().getName());
    }

BigDecimal 转换成 int数据类型

    //bigDecimal  转换成  int类型
        public static void bigDecimalToInt(){
            BigDecimal b = new BigDecimal(12);            int c = b.intValue();
        }


  • 2019-05-25 14:54:50

    commit your changes or stash them before you can merge

    Your local changes to the following files would be overwritten by merge:         protected/config/main.php Please, commit your changes or stash them before you can merge. --------------------- 作者:陈小峰_iefreer 来源:CSDN 原文:https://blog.csdn.net/iefreer/article/details/7679631 版权声明:本文为博主原创文章,转载请附上博文链接!

  • 2019-05-27 10:43:34

    IntelliJ IDEA中C盘文件过大怎么办

    当我在D:\ 安装完IDEA9.0之后,建立了一个工程,发现C:\Users\Administrator\.IntelliJIdea90 竟然增大到了500+M,并且随着使用在逐渐增大,这样占用系统盘资源是非常让人不爽的,那么如何将其修改到其他路径呢?

  • 2019-05-28 13:33:20

    BRVAH+MTRVA,复杂?不存在的

    言归正传,这样的一个首页,我们需要做怎么样的基础工作呢?或者说,碰到以后更复杂的页面我们应该怎么做?这里小提示下,不要再用什么类似ScrollView的这种东西了,诶,好像说的有点绝对,尽量不要用,这不是谷歌想要看到的,5.0谷歌推出了RecyclerView,从它的整个设计架构来看,简直就是为这而生的。而RecyclerView的视图是通过Adapter来渲染的。原始的Adapter,让人很蛋疼,重复工作太多,我们应该要有封装的思想,把最需要的部分提供出来,其它不用管。

  • 2019-05-29 14:19:19

    解决Git中fatal: refusing to merge unrelated histories

    Git的报错 在使用Git的过程中有时会出现一些问题,那么在解决了每个问题的时候,都需要去总结记录下来,下次不再犯。 一、fatal: refusing to merge unrelated histories 今天在使用Git创建项目的时候,在两个分支合并的时候,出现了下面的这个错误。

  • 2019-05-29 15:47:51

    撤销commit

    在git push的时候,有时候我们会想办法撤销git commit的内容