当前位置:网站首页>Comparison of two BigDecimal data types, addition, subtraction, multiplication and division, and formatting
Comparison of two BigDecimal data types, addition, subtraction, multiplication and division, and formatting
2022-06-10 13:01:00 【yechaoa】
In general ,string For type comparison equals,int use =
and BigDecimal Need to use compareTo
if(goodsData.unitPrice.compareTo(new BigDecimal("0.00"))==0){
etGoodsPrice.setText("");
}else{
etGoodsPrice.setText(String.valueOf(goodsData.unitPrice));
}The above code is just two BigDecimal Compare values of data types
new BigDecimal("0.00") Is to determine the data format , Two decimal places
==0, It's also described in the document ,0 It means equal ,-1 Say less than ,1 Greater than
Add, subtract, multiply and divide :
BigDecimal b=new BigDecimal(100);
Suppose a int value :int c=5; If it is BigDecimal Type does not need to be converted
1. Add
b.add(BigDecimal.valueOf(c));
2. reduce
b.subtract(BigDecimal.valueOf(c));
3. ride
b.multiply(BigDecimal.valueOf(c));
4. except
b.divide(BigDecimal.valueOf(c));
format :
.setScale(2) Keep two decimal places , Default rounding , 1.235》1.24
.setScale(2,BigDecimal.ROUND_DOWN) Directly delete the decimal after two decimal places , 1.235》1.23
.setScale(2,BigDecimal.ROUND_HALF_UP) rounding , Take up , 1.235》1.24
.setScale(2,BigDecimal.ROUND_HALF_DOWN) rounding , Take down , 1.235》1.23
边栏推荐
- 【移动机器人】轮式里程计原理
- Office technical lecture: punctuation - English - Encyclopedia
- CVPR2022|AConvNetforthe2020s&如何设计神经网络总结
- Alibaba cloud ECS server builds MySQL database
- 今天,一对情侣拿下香港最大电商IPO
- 由文件图形丢失,说明自己都不用自己开发的OFFICE
- Software project management 6.10 Cost budget
- VDMA调试总结
- Start with interpreting the code automatically generated by BDC, and explain the program components of sapgui
- 向数据库中注册用户名和密码的功能
猜你喜欢

What if the xshell evaluation period has expired? Follow the steps below to solve the problem!

Program, calculate 2/1+3/2+5/3+8/5 Value of. It is required to calculate the sum of the first n items and keep 2 decimal places (starting from the second item of the sequence, the numerator of each it
![Vdo-slam source code reading notes [1] dynamic obj part in track()](/img/18/7260d5b8dba4dcdb64d7f299198ad0.png)
Vdo-slam source code reading notes [1] dynamic obj part in track()

Count the number and average value of natural numbers whose sum of bits within 100 is 7

Practical cases, in-depth analysis

In June, 2022, China Database ranking: tidb made a comeback to win the crown, and Dameng was dormant and won the flowers in May

Give root password for maintenace (or press Control-D to continue):解决方法

Offer has been made, advanced learning

20-year technical veteran gives up his CTO title! Why did the startup attract him?

Mobile phone manufacturers "go back to their ancestors", only apple said no
随机推荐
Leetcode 96. Différents arbres de recherche binaires
Request to obtain the IP address of the request server
MySQL service evolution
Tensorflow2.0进阶学习-图像 (十一)
JS array to JSON, JSON to array. Array to comma separated string, string to array
OFFICE技术讲座:标点符号-中文-竖排
【移动机器人】轮式里程计原理
Wechat web development tool tutorial, the company develops Web
软件项目管理 6.10.成本预算
Oceanbase, phase II of the document promotion plan, invites you to jointly build documents
【FAQ】运动健康服务REST API接口使用过程中常见问题和解决方法总结
Qt数据库应用22-文件编码格式识别
IQR箱线图
Don't mistake "it informatization" for "super project"
从解读 BDC 自动生成的代码谈起,讲解 SAPGUI 的程序组成部分
(1) Pretreatment summary
Good article sharing | 48 hour agile development introduction
Altium Designer重拾之学习资料推荐
Ant financial services Yang Jun: evolution of ant data analysis platform and application of data analysis methods
[golang] when creating a structure with configuration parameters, how should the optional parameters be transferred?