广州北大青鸟计算机职业培训学校
互联网技术培训、软件技术培训、大数据培训、云计算培训、数据分析培训信息网
当前位置:网站首页 > 软件教程 > Java技术 > 正文

惠州如何处理bigdecimal小数位?_北大青鸟IT学校

作者:邓华发布时间:2021-06-10分类:Java技术浏览:914


导读:Java是现在非常主流的编程语言之一,很多人想转行学习IT,首选Java语言。那么如何处理bigdecimal小数位?下面就让我们一起来看看惠州北大青鸟老师是怎么回答的。

Java是现在非常主流的编程语言之一,很多人想转行学习IT,首选Java语言。那么如何处理bigdecimal小数位?下面就让我们一起来看看惠州北大青鸟老师是怎么回答的。

复制代码

  1. public class test1_format {

  2. public static void main(String[] args) { BigDecimal decimal = new BigDecimal("1.12345"); System.out.println(decimal); BigDecimal setScale = decimal.setScale(4,BigDecimal.ROUND_HALF_DOWN); System.out.println(setScale);

  3.        BigDecimal setScale1 = decimal.setScale(4,BigDecimal.ROUND_HALF_UP);    System.out.println(setScale1);}

  4. }

}

小数位处理.png

参数定义


ROUND_CEILING Rounding mode to round towards positive infinity. 向正无穷方向舍入

  1. ROUND_DOWN 

  2. Rounding mode to round towards zero. 

  3. 向零方向舍入 



  1. ROUND_FLOOR 

  2. Rounding mode to round towards negative infinity. 

  3. 向负无穷方向舍入 


  1. ROUND_HALF_DOWN 

  2. Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down. 

  3. 向(距离)最近的一边舍入,除非两边(的距离)是相等,如果是这样,向下舍入, 例如1.55 保留一位小数结果为1.5 


  1. ROUND_HALF_EVEN 

  2. Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor. 

  3. 向(距离)最近的一边舍入,除非两边(的距离)是相等,如果是这样,如果保留位数是奇数,使用ROUND_HALF_UP ,如果是偶数,使用ROUND_HALF_DOWN 


  1. ROUND_HALF_UP 

  2. Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up. 

  3. 向(距离)最近的一边舍入,除非两边(的距离)是相等,如果是这样,向上舍入, 1.55保留一位小数结果为1.6 


  1. ROUND_UNNECESSARY 

  2. Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary. 

  3. 计算结果是精确的,不需要舍入模式 

ROUND_UP Rounding mode to round away from zero. 向远离0的方向舍入

想了解更多关于Java的资讯吗?可以来惠州北大青鸟新方舟校区了解一下。

Java13.png

Java


标签:惠州计算机JAVA软件开发惠州计算机Java软件开发惠州计算机JAVA培训惠州计算机JAVA软件开发学校惠州计算机Java软件开发培训JAVAJava软件开发北大青鸟IT计算机学校北大青鸟IT软件学校北大青鸟IT学校


Java技术排行
标签列表
网站分类
文章归档
最近发表