当前位置:网站首页>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
边栏推荐
- Huawei machine test question: splicing URL
- MySQL tuning --01--- optimization steps and system performance parameters
- What are the reasons why most webmasters choose Hong Kong site group servers?
- Technology inventory: past, present and future of Message Oriented Middleware
- Data7202 statistical analysis
- Guess the size of the number
- SAP ui5 Application Development Tutorial Part 30 - parameter transfer in the routing process of SAP ui5
- Wechat applet authorization login + mobile phone sending verification code +jwt verification interface (laravel8+php)
- Netstat command – displays network status
- At the age of 26, I was transferred to software testing with zero foundation. Now I have successfully entered the job with a monthly salary of 12K. However, no one understands my bitterness
猜你喜欢
Soft exam information system project manager_ Information system security management - Senior Information System Project Manager of soft test 026
Mongodb delete data
[network security] sharing of experience and ideas of an emergency battle
Soft exam information system project manager_ Management Science (Operations Research) 2--- senior information system project manager of soft test 034
Click to send text messages without response is a common problem for many users in building the elegant grass Dragonfly Q system - solve the problem of clicking to send text messages without response
Pre knowledge of asynchronous operation
Wind farm visualization: wind farm data
Guess the size of the number
[Suanli network] technological innovation of Suanli Network -- Key Technologies of green and security
Wechat applet authorization login + mobile phone sending verification code +jwt verification interface (laravel8+php)
随机推荐
Interview experience - list of questions
JS to realize the encapsulation of the function of obtaining the mouse click position
What elements are indispensable for the development of the character? What are the stages
Research Report on demand and Competitive Prospect of global and Chinese welding personal protective equipment industry 2022-2027
Grep command – powerful text search tool
Analysis report on global and Chinese pharmaceutical excipients industry competition and marketing model 2022-2028
How to open an account online? Is it safe to open an account online?
Global and Chinese medical protective clothing market supply and demand research and investment value proposal report 2022-2028
Analysis report on production and sales demand and sales prospect of global and Chinese phosphating solution Market 2022-2028
CST8227
[data visualization application] draw spatial map (with R language code)
Monitoring access: how to grant minimum WMI access to the monitoring service account
Mount command - file system mount
[road of system analyst] collection of wrong questions in the chapters of Applied Mathematics and economic management
Lesson 8: FTP server setup and loading
SAP ui5 beginner tutorial No. 28 - Introduction to the integration test tool OPA for SAP ui5 applications
SAP Fiori tools and corresponding cli (command line interface)
MySQL transaction learning notes (I) first encounter
What is the IP address
[Suanli network] technological innovation of Suanli Network -- Key Technologies of green and security