当前位置:网站首页>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
边栏推荐
- Processes and threads - concepts and process scheduling
- cacacahe
- [kicad image] download and installation
- Asemi fast recovery diode us1m parameters, us1m recovery time, us1m voltage drop
- Gavin's insight on transformer live class - line by line analysis and field experiment analysis of insurance BOT microservice code of insurance industry in the actual combat of Rasa dialogue robot pro
- MySQL uses the where condition to find strange results: solve
- [kicad image] download and installation
- Location object
- Research Report on marketing channel analysis and competitive strategy of China's polycarbonate industry 2022
- Methods for obtaining some information of equipment
猜你喜欢

Day21 performance test process

C simple operation mongodb
Technology inventory: Technology Evolution and Future Trend Outlook of cloud native Middleware

Folding mobile phones are expected to explode, or help Samsung compete with apple and Chinese mobile phones

Mongodb delete data

Tablespace free space

Understanding the dynamic mode of mongodb document
[golang] leetcode intermediate - Search rotation sort array & search two-dimensional matrix II

【LeetCode】40. Combined summation II (2 strokes of wrong questions)

General test point ideas are summarized and shared, which can be directly used in interview and actual software testing
随机推荐
Observation configuring wmic
Tencent and China Mobile continued to buy back with large sums of money, and the leading Hong Kong stocks "led" the market to rebound?
Technology Review: Interpretation of cloud native architecture trend in 2022
PHP output (print) log to TXT text
Research Report on brand strategic management and marketing trends in the global and Chinese preserved fruit market 2022
Fdisk command – disk partition
After five years of software testing in ByteDance, I was dismissed in December to remind my brother of paddling
SAP Fiori tools and corresponding cli (command line interface)
Global and Chinese medical protective clothing market supply and demand research and investment value proposal report 2022-2028
[road of system analyst] collection of wrong questions in the chapters of Applied Mathematics and economic management
Trial version of routing history and routing back and history of SAP ui5
Optimal Parking
Mongodb basic concept learning - set
Noi Mathematics: Dirichlet convolution
Global and China financial guarantee marketing strategy and channel dynamic construction report 2022
cacacahe
[data visualization application] draw spatial map (with R language code)
Research Report on marketing channel analysis and competitive strategy of China's polycarbonate industry 2022
What is hybrid web containers for SAP ui5
How SAP ui5 device type detection device API works