当前位置:网站首页>BigDecimal. Summary of setscale usage
BigDecimal. Summary of setscale usage
2022-06-25 06:19:00 【WD Technology】
- ROUND_DOWN( Directly omit the contents after the specified number of digits )
BigDecimal bigDecimal = new BigDecimal(“2.125456”).setScale(2, BigDecimal.ROUND_DOWN);
System.out.println(bigDecimal ); // result :2.12
- ROUND_UP( Directly perform one bit processing on the content after the specified number of bits )
BigDecimal bigDecimal = new BigDecimal(“2.125456”).setScale(2, BigDecimal.ROUND_UP);
System.out.println(bigDecimal); // result :2.13
- ROUND_CEILING( Positive numbers use ROUND_UP The rules , Negative numbers use ROUND_DOWN The rules )
BigDecimal bigDecimalA = new BigDecimal(“2.125456”).setScale(2, BigDecimal.ROUND_CEILING);
System.out.println(bigDecimalA);// result :2.13
BigDecimal bigDecimalB = new BigDecimal("-2.125456").setScale(2, BigDecimal.ROUND_CEILING);
System.out.println(bigDecimalB);// result :2.12
- ROUND_FLOOR( Positive numbers omit content , Negative numbers go down one digit )
BigDecimal bigDecimalA = new BigDecimal(“2.125456”).setScale(2, BigDecimal.ROUND_FLOOR);
System.out.println(bigDecimalA);// result :2.12
BigDecimal bigDecimalB = new BigDecimal("-2.125456").setScale(2, BigDecimal.ROUND_FLOOR);
System.out.println(bigDecimalB);// result :-2.13
- ROUND_HALF_UP,ROUND_HALF_DOWN( rounding )
BigDecimal bigDecimalA = new BigDecimal(“2.125456”).setScale(2, BigDecimal.ROUND_HALF_UP);
System.out.println(bigDecimalA);// result :2.13
BigDecimal bigDecimalB = new BigDecimal("-2.125456").setScale(2, BigDecimal.ROUND_HALF_DOWN);
System.out.println(bigDecimalB);// result :-2.13
- ROUND_HALF_EVEN( If the first digit of the specified decimal place is an odd number, it will be rounded to the last digit , If it is an even number, the contents after the specified decimal places will be discarded )
BigDecimal bigDecimalA = new BigDecimal(“2.113”).setScale(2, BigDecimal.ROUND_HALF_EVEN);
System.out.println(bigDecimalA);// result :2.11 Although it is an odd number , however 3<5, No carry
BigDecimal bigDecimalB = new BigDecimal(“2.115”).setScale(2, BigDecimal.ROUND_HALF_EVEN);
System.out.println(bigDecimalB);// result :2.12 Because it is an odd number and conforms to " Five in ", Then carry
This rounding mode is also known as “ Banker's Rounding ”, Mainly used in the United States . Round to the nearest , In two fifths .
If the previous one is odd , Then enter , Otherwise, give up .
8.ROUND_UNNECESSARY( Assert that the requested operation has exact results , So no rounding is required .)
If this rounding mode is specified for the operation to get accurate results , Throw out ArithmeticException
边栏推荐
- What is the IP address
- Gb28181 protocol -- timing
- Understanding the dynamic mode of mongodb document
- MV command – move or rename files
- The e-book "action guide for large organizations to further promote zero code application platform" was officially released!
- Research Report on investment share and application prospect of 1,3-propanediol (PDO) industry in the world and China 2022
- The sum problem
- Tablespace free space
- Folding mobile phones are expected to explode, or help Samsung compete with apple and Chinese mobile phones
- The elephant turns around and starts the whole body. Ali pushes Maoxiang not only to Jingdong
猜你喜欢
Vscode voice notes to enrich information (medium)

Tablespace free space
SAP ui5 beginner tutorial 25 - using proxy server to solve the cross domain problem of SAP ui5 application accessing remote OData service trial version

MySQL tuning --01--- optimization steps and system performance parameters
Websocket in the promotion of vegetable farmers

Uni app wechat applet customer service chat function
SAP ui5 beginner tutorial No. 28 - Introduction to the integration test tool OPA for SAP ui5 applications
[golang] leetcode intermediate - Search rotation sort array & search two-dimensional matrix II
SAP ui5 application development tutorial XXIX - Introduction to routing and navigation functions of SAP ui5 trial version

What happens when redis runs out of memory
随机推荐
Curl command – file transfer tool
Folding mobile phones are expected to explode, or help Samsung compete with apple and Chinese mobile phones
Rhcsa--- day 6 operation
Ifconfig command – displays or sets network devices
Global and Chinese benzoic acid market competition strategy and demand scale forecast report 2022
How to open an account online? Is it safe to open an account online?
Huawei machine test question: splicing URL
MySQL uses the where condition to find strange results: solve
DF command – displays disk space usage
Uni app wechat applet customer service chat function
Understanding the dynamic mode of mongodb document
Soft exam information system project manager_ Management Science (Operations Research) -- senior information system project manager of soft test 033
Es11 new methods: dynamic import(), bigint, globalthis, optional chain, and null value merging operator
TFTP command – uploading and downloading files
Global and Chinese kaolin market operation scale and investment development proposal report 2022
Monitoring access: how to grant minimum WMI access to the monitoring service account
Websocket in the promotion of vegetable farmers
What does cardinality mean in set
Research Report on marketing channel analysis and competitive strategy of China's polycarbonate industry 2022
Add the author watermark plugin v1.4 update to the posts of elegant grass discuz plugin - some forums post errors and bugs have been fixed