public class MathUtils
extends java.lang.Object
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
DEFAULT_DIV_SCALE
默认除法运算精度。
|
| 构造器和说明 |
|---|
MathUtils()
默认构造函数。
|
| 限定符和类型 | 方法和说明 |
|---|---|
static double |
add(double v1,
double v2)
提供精确的加法运算。
|
static java.lang.String |
add(java.lang.String v1,
java.lang.String v2)
提供精确的加法运算。
|
static double |
divide(double v1,
double v2)
提供(相对)精确的除法运算。
|
static double |
divide(double v1,
double v2,
int scale)
提供(相对)精确的除法运算。
|
static double |
divide(double v1,
double v2,
int scale,
int round_mode)
提供(相对)精确的除法运算。
|
static java.lang.String |
divide(java.lang.String v1,
java.lang.String v2)
提供(相对)精确的除法运算。
|
static java.lang.String |
divide(java.lang.String v1,
java.lang.String v2,
int scale)
提供(相对)精确的除法运算。
|
static java.lang.String |
divide(java.lang.String v1,
java.lang.String v2,
int scale,
int round_mode)
提供(相对)精确的除法运算。
|
static double |
multiply(double v1,
double v2)
提供精确的乘法运算。
|
static java.lang.String |
multiply(java.lang.String v1,
java.lang.String v2)
提供精确的乘法运算
|
static double |
round(double v,
int scale)
提供精确的小数位四舍五入处理。
|
static double |
round(double v,
int scale,
int round_mode)
提供精确的小数位四舍五入处理。
|
static java.lang.String |
round(java.lang.String v,
int scale)
提供精确的小数位四舍五入处理。
|
static java.lang.String |
round(java.lang.String v,
int scale,
int round_mode)
提供精确的小数位四舍五入处理。
|
static double |
subtract(double v1,
double v2)
提供精确的减法运算。
|
static java.lang.String |
subtract(java.lang.String v1,
java.lang.String v2)
提供精确的减法运算。
|
public static final int DEFAULT_DIV_SCALE
public static double add(double v1,
double v2)
v1 - v2 - public static java.lang.String add(java.lang.String v1,
java.lang.String v2)
v1 - v2 - public static double subtract(double v1,
double v2)
v1 - v2 - public static java.lang.String subtract(java.lang.String v1,
java.lang.String v2)
v1 - v2 - public static double multiply(double v1,
double v2)
v1 - v2 - public static java.lang.String multiply(java.lang.String v1,
java.lang.String v2)
v1 - v2 - public static double divide(double v1,
double v2)
v1 - v2 - public static double divide(double v1,
double v2,
int scale)
v1 - v2 - scale - 表示需要精确到小数点以后几位。public static double divide(double v1,
double v2,
int scale,
int round_mode)
v1 - v2 - scale - 表示需要精确到小数点以后几位。round_mode - 表示用户指定的舍入模式。
BigDecimal 中定义的舍入模式:
static int
ROUND_CEILING
Rounding mode to round towards positive infinity.
向正无穷方向舍入
static int
ROUND_DOWN
Rounding mode to round towards zero.
向零方向舍入
static int
ROUND_FLOOR
Rounding mode to round towards negative infinity.
向负无穷方向舍入
static int
ROUND_HALF_DOWN
Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down.
向(距离)最近的一边舍入,除非两边(的距离)是相等,如果是这样,向下舍入, 例如1.55 保留一位小数结果为1.5
static int
ROUND_HALF_EVEN
Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor.
向(距离)最近的一边舍入,除非两边(的距离)是相等,如果是这样,如果保留位数是奇数,使用ROUND_HALF_UP ,如果是偶数,使用ROUND_HALF_DOWN
static int
ROUND_HALF_UP
Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.
向(距离)最近的一边舍入,除非两边(的距离)是相等,如果是这样,向上舍入, 1.55保留一位小数结果为1.6
static int
ROUND_UNNECESSARY
Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary.
计算结果是精确的,不需要舍入模式
static int
ROUND_UP
Rounding mode to round away from zero.
向远离0的方向舍入
java.math.BigDecimal.ROUND_CEILING,
java.math.BigDecimal.ROUND_DOWN,
java.math.BigDecimal.ROUND_FLOOR,
java.math.BigDecimal.ROUND_HALF_DOWN,
java.math.BigDecimal.ROUND_HALF_EVEN,
java.math.BigDecimal.ROUND_HALF_UP,
java.math.BigDecimal.ROUND_UNNECESSARY,
java.math.BigDecimal.ROUND_UPpublic static java.lang.String divide(java.lang.String v1,
java.lang.String v2)
v1 - v2 - public static java.lang.String divide(java.lang.String v1,
java.lang.String v2,
int scale)
v1 - v2 - scale - 表示需要精确到小数点以后几位。public static java.lang.String divide(java.lang.String v1,
java.lang.String v2,
int scale,
int round_mode)
v1 - v2 - scale - 表示需要精确到小数点以后几位。round_mode - 表示用户指定的舍入模式。
BigDecimal 中定义的舍入模式:
static int
ROUND_CEILING
Rounding mode to round towards positive infinity.
向正无穷方向舍入
static int
ROUND_DOWN
Rounding mode to round towards zero.
向零方向舍入
static int
ROUND_FLOOR
Rounding mode to round towards negative infinity.
向负无穷方向舍入
static int
ROUND_HALF_DOWN
Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down.
向(距离)最近的一边舍入,除非两边(的距离)是相等,如果是这样,向下舍入, 例如1.55 保留一位小数结果为1.5
static int
ROUND_HALF_EVEN
Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor.
向(距离)最近的一边舍入,除非两边(的距离)是相等,如果是这样,如果保留位数是奇数,使用ROUND_HALF_UP ,如果是偶数,使用ROUND_HALF_DOWN
static int
ROUND_HALF_UP
Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.
向(距离)最近的一边舍入,除非两边(的距离)是相等,如果是这样,向上舍入, 1.55保留一位小数结果为1.6
static int
ROUND_UNNECESSARY
Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary.
计算结果是精确的,不需要舍入模式
static int
ROUND_UP
Rounding mode to round away from zero.
向远离0的方向舍入
java.math.BigDecimal.ROUND_CEILING,
java.math.BigDecimal.ROUND_DOWN,
java.math.BigDecimal.ROUND_FLOOR,
java.math.BigDecimal.ROUND_HALF_DOWN,
java.math.BigDecimal.ROUND_HALF_EVEN,
java.math.BigDecimal.ROUND_HALF_UP,
java.math.BigDecimal.ROUND_UNNECESSARY,
java.math.BigDecimal.ROUND_UPpublic static double round(double v,
int scale)
v - 需要四舍五入的数字。scale - 小数点后保留几位。public static double round(double v,
int scale,
int round_mode)
v - 需要四舍五入的数字。scale - 小数点后保留几位。round_mode - 指定的舍入模式。
BigDecimal 中定义的舍入模式:
static int
ROUND_CEILING
Rounding mode to round towards positive infinity.
向正无穷方向舍入
static int
ROUND_DOWN
Rounding mode to round towards zero.
向零方向舍入
static int
ROUND_FLOOR
Rounding mode to round towards negative infinity.
向负无穷方向舍入
static int
ROUND_HALF_DOWN
Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down.
向(距离)最近的一边舍入,除非两边(的距离)是相等,如果是这样,向下舍入, 例如1.55 保留一位小数结果为1.5
static int
ROUND_HALF_EVEN
Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor.
向(距离)最近的一边舍入,除非两边(的距离)是相等,如果是这样,如果保留位数是奇数,使用ROUND_HALF_UP ,如果是偶数,使用ROUND_HALF_DOWN
static int
ROUND_HALF_UP
Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.
向(距离)最近的一边舍入,除非两边(的距离)是相等,如果是这样,向上舍入, 1.55保留一位小数结果为1.6
static int
ROUND_UNNECESSARY
Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary.
计算结果是精确的,不需要舍入模式
static int
ROUND_UP
Rounding mode to round away from zero.
向远离0的方向舍入
java.math.BigDecimal.ROUND_CEILING,
java.math.BigDecimal.ROUND_DOWN,
java.math.BigDecimal.ROUND_FLOOR,
java.math.BigDecimal.ROUND_HALF_DOWN,
java.math.BigDecimal.ROUND_HALF_EVEN,
java.math.BigDecimal.ROUND_HALF_UP,
java.math.BigDecimal.ROUND_UNNECESSARY,
java.math.BigDecimal.ROUND_UPpublic static java.lang.String round(java.lang.String v,
int scale)
v - 需要四舍五入的数字。scale - 小数点后保留几位。public static java.lang.String round(java.lang.String v,
int scale,
int round_mode)
v - 需要四舍五入的数字。scale - 小数点后保留几位。round_mode - 指定的舍入模式。
BigDecimal 中定义的舍入模式:
static int
ROUND_CEILING
Rounding mode to round towards positive infinity.
向正无穷方向舍入
static int
ROUND_DOWN
Rounding mode to round towards zero.
向零方向舍入
static int
ROUND_FLOOR
Rounding mode to round towards negative infinity.
向负无穷方向舍入
static int
ROUND_HALF_DOWN
Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down.
向(距离)最近的一边舍入,除非两边(的距离)是相等,如果是这样,向下舍入, 例如1.55 保留一位小数结果为1.5
static int
ROUND_HALF_EVEN
Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor.
向(距离)最近的一边舍入,除非两边(的距离)是相等,如果是这样,如果保留位数是奇数,使用ROUND_HALF_UP ,如果是偶数,使用ROUND_HALF_DOWN
static int
ROUND_HALF_UP
Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.
向(距离)最近的一边舍入,除非两边(的距离)是相等,如果是这样,向上舍入, 1.55保留一位小数结果为1.6
static int
ROUND_UNNECESSARY
Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary.
计算结果是精确的,不需要舍入模式
static int
ROUND_UP
Rounding mode to round away from zero.
向远离0的方向舍入
java.math.BigDecimal.ROUND_CEILING,
java.math.BigDecimal.ROUND_DOWN,
java.math.BigDecimal.ROUND_FLOOR,
java.math.BigDecimal.ROUND_HALF_DOWN,
java.math.BigDecimal.ROUND_HALF_EVEN,
java.math.BigDecimal.ROUND_HALF_UP,
java.math.BigDecimal.ROUND_UNNECESSARY,
java.math.BigDecimal.ROUND_UPCopyright © 2001-2014 hynnet.com