当前位置:网站首页>BigDecimal中divide方法
BigDecimal中divide方法
2022-07-17 05:21:00 【yygyj】
1、首先说一下用法,BigDecimal中的divide主要就是用来做除法的运算。其中有这么一个方法.
public BigDecimal divide(BigDecimal divisor,int scale, int roundingMode)
第一个参数是除数,第二个参数代表保留几位小数,第三个代表的是使用的模式。
BigDecimal.ROUND_DOWN:直接省略多余的小数,比如1.28如果保留1位小数,得到的就是1.2
BigDecimal.ROUND_UP:直接进位,比如1.21如果保留1位小数,得到的就是1.3BigDecimal.ROUND_HALF_UP:四舍五入,2.35保留1位,变成2.4BigDecimal.ROUND_HALF_DOWN:四舍五入,2.35保留1位,变成2.3后边两种的区别就是如果保留的位数的后一位如果正好是5的时候,一个舍弃掉,一个进位。
2、BigDecimal.setScale()方法用于格式化小数点
setScale(1)表示保留一位小数,默认用四舍五入方式
setScale(1,BigDecimal.ROUND_DOWN)直接删除多余的小数位,如2.35会变成2.3
setScale(1,BigDecimal.ROUND_UP)进位处理,2.35变成2.4
setScale(1,BigDecimal.ROUND_HALF_UP)四舍五入,2.35变成2.4
setScaler(1,BigDecimal.ROUND_HALF_DOWN)四舍五入,2.35变成2.3,如果是5则向下舍
边栏推荐
- 开发板训练:STM32下的多任务程序
- 实验一 简单程序设计
- oracle中merge into 与update的性能对比
- ANAME
- Local makefile compile other folder files specify obj directory
- 渣渣学习之路(2)纯小白向:Win Server 2003服务器搭建
- Restapi implements aggregation (dark horse tutorial)
- 简单irules编写 入门级
- Design and implementation of a gesture control system for tablet computer based on gaze
- DSL realizes automatic completion query
猜你喜欢

Programming learning based on ardunio ide software development

Share the application cases of CS brand patch T card in the field of hunting camera

Query of database (II)

Solution: unable to load file c:\program files\ Because running scripts is forbidden on this system

Application of views and index files

吴恩达机器学习第14-15章

常见的用户密码加密方式以及破解方法

Hand in hand building a home NAS universal server (1) | configuration selection and preparation

吴恩达机器学习第10-11章

使用Altium Designer软件绘制一个基于stm32设计
随机推荐
通过数据加密方案阻止勒索攻击
redis
Experiment 4 operator overloading and virtual functions
STM32的PWM和DAC练习中生成音频和波形
Wu Enda machine learning chapter 6-7
Automatic completion & (custom) Pinyin word Separator &
促进数字世界的信任
网络中的一些基本概念
从零开始的 Rust 语言 blas 库之预备篇(2)—— blas 矩阵格式详解
二分查找及其引申
Wu Enda machine learning chapter 8-9
Some problems encountered in work
基于I2C的温度采集实验及实验心得
企业数据治理之勒索病毒篇
DSL implements bucket aggregation
[jmeter] TCP Sampler
Pytorch deep learning practice-b station Liu erden-day7
oracle中merge into 与update的性能对比
@resource is popular in idea
Introduction to daily use of manjaro system