File was renamed from fanli/src/main/java/com/yeshi/fanli/util/MoneyBigDecimalUtil.java |
| | |
| | | package com.yeshi.fanli.util;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | |
|
| | | public class MoneyBigDecimalUtil {
|
| | |
|
| | | public static BigDecimal add(BigDecimal v1, BigDecimal v2) {
|
| | | return v1.add(v2).setScale(2, BigDecimal.ROUND_DOWN);
|
| | | }
|
| | |
|
| | | public static BigDecimal sub(BigDecimal b1, BigDecimal b2) {
|
| | | return b1.subtract(b2).setScale(2, BigDecimal.ROUND_DOWN);
|
| | | }
|
| | |
|
| | | public static BigDecimal mul(BigDecimal d1, BigDecimal d2) { // 进行乘法运算
|
| | | return d1.multiply(d2).setScale(2, BigDecimal.ROUND_DOWN);
|
| | | }
|
| | |
|
| | | public static BigDecimal mul2(BigDecimal d1, BigDecimal d2) { // 进行乘法运算
|
| | | return d1.multiply(d2).setScale(2, BigDecimal.ROUND_DOWN);
|
| | | }
|
| | | |
| | | public static BigDecimal mul(BigDecimal d1, BigDecimal d2,int scale) { // 进行乘法运算
|
| | | return d1.multiply(d2).setScale(scale, BigDecimal.ROUND_DOWN);
|
| | | }
|
| | |
|
| | | public static BigDecimal div(BigDecimal d1, BigDecimal d2) {// 进行除法运算
|
| | | return d1.divide(d2, 2, BigDecimal.ROUND_DOWN);
|
| | | }
|
| | |
|
| | | public static BigDecimal divUp(BigDecimal d1, BigDecimal d2) {// 进行除法运算
|
| | | return d1.divide(d2, 2, BigDecimal.ROUND_UP);
|
| | | }
|
| | |
|
| | | public static BigDecimal div3(BigDecimal d1, BigDecimal d2) {// 进行除法运算
|
| | | return d1.divide(d2, 3, BigDecimal.ROUND_DOWN);
|
| | | }
|
| | | |
| | | public static BigDecimal div(BigDecimal d1, BigDecimal d2,int scale) {// 进行除法运算
|
| | | return d1.divide(d2, scale, BigDecimal.ROUND_DOWN);
|
| | | }
|
| | |
|
| | | public static BigDecimal getWithNoZera(BigDecimal num) {// 进行除法运算
|
| | | while (num.toString().endsWith("0") && num.toString().indexOf(".") > -1) {
|
| | | num = new BigDecimal(num.toString().substring(0, num.toString().length() - 1));
|
| | | return getWithNoZera(num);
|
| | | }
|
| | | return num;
|
| | | }
|
| | |
|
| | | }
|
| | | package org.yeshi.utils; |
| | | |
| | | import java.math.BigDecimal; |
| | | |
| | | public class MoneyBigDecimalUtil { |
| | | |
| | | public static BigDecimal add(BigDecimal v1, BigDecimal v2) { |
| | | return v1.add(v2).setScale(2, BigDecimal.ROUND_DOWN); |
| | | } |
| | | |
| | | public static BigDecimal sub(BigDecimal b1, BigDecimal b2) { |
| | | return b1.subtract(b2).setScale(2, BigDecimal.ROUND_DOWN); |
| | | } |
| | | |
| | | public static BigDecimal mul(BigDecimal d1, BigDecimal d2) { // 进行乘法运算 |
| | | return d1.multiply(d2).setScale(2, BigDecimal.ROUND_DOWN); |
| | | } |
| | | |
| | | public static BigDecimal mul2(BigDecimal d1, BigDecimal d2) { // 进行乘法运算 |
| | | return d1.multiply(d2).setScale(2, BigDecimal.ROUND_DOWN); |
| | | } |
| | | |
| | | public static BigDecimal mul(BigDecimal d1, BigDecimal d2,int scale) { // 进行乘法运算 |
| | | return d1.multiply(d2).setScale(scale, BigDecimal.ROUND_DOWN); |
| | | } |
| | | |
| | | public static BigDecimal div(BigDecimal d1, BigDecimal d2) {// 进行除法运算 |
| | | return d1.divide(d2, 2, BigDecimal.ROUND_DOWN); |
| | | } |
| | | |
| | | public static BigDecimal divUp(BigDecimal d1, BigDecimal d2) {// 进行除法运算 |
| | | return d1.divide(d2, 2, BigDecimal.ROUND_UP); |
| | | } |
| | | |
| | | public static BigDecimal div3(BigDecimal d1, BigDecimal d2) {// 进行除法运算 |
| | | return d1.divide(d2, 3, BigDecimal.ROUND_DOWN); |
| | | } |
| | | |
| | | public static BigDecimal div(BigDecimal d1, BigDecimal d2,int scale) {// 进行除法运算 |
| | | return d1.divide(d2, scale, BigDecimal.ROUND_DOWN); |
| | | } |
| | | |
| | | public static BigDecimal getWithNoZera(BigDecimal num) {// 进行除法运算 |
| | | while (num.toString().endsWith("0") && num.toString().indexOf(".") > -1) { |
| | | num = new BigDecimal(num.toString().substring(0, num.toString().length() - 1)); |
| | | return getWithNoZera(num); |
| | | } |
| | | return num; |
| | | } |
| | | |
| | | } |