public class Arith extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static BigDecimal |
HANDRED
表示数值 100(一百) 的BigDecimal
|
static BigDecimal |
HANDRED_MILLION
表示数值 100 000 000(一亿) 的BigDecimal
|
static BigDecimal |
MYRIAD
表示数值 10 000(一万) 的BigDecimal
|
static BigDecimal |
ONE
表示数值 1(一) 的BigDecimal
|
static BigDecimal |
TEN
表示数值 10(一十) 的BigDecimal
|
static BigDecimal |
THOUSAND
表示数值 1000(一千) 的BigDecimal
|
protected BigDecimal |
value |
static BigDecimal |
ZERO
表示数值 0(零) 的BigDecimal
|
| 构造器和说明 |
|---|
Arith()
构造一个默认值为0的商业计算数
|
Arith(BigDecimal d)
构造一个为指定double值的商业计算数
|
Arith(boolean d)
构造一个指定boolean值的商业计算数。
|
Arith(double d)
构造一个为指定值的商业计算数
|
Arith(int d)
构造一个指定int值的商业计算数
|
Arith(long d)
构造一个指定long值的商业计算数
|
Arith(Object d)
构造一个指定Object值的商业计算数
|
Arith(String d)
构造一个为指定值(字符串形式)的商业计算数
|
| 限定符和类型 | 方法和说明 |
|---|---|
Arith |
add(BigDecimal d)
商业加法运算
|
Arith |
add(double d)
商业加法运算
|
static double |
add(double a,
double b)
商业加法运算
|
Arith |
add(long d)
商业加法运算
|
Arith |
add(String d)
商业加法运算
|
byte |
byteValue()
转换为byte值
|
static boolean |
canDivideExactly(BigDecimal d,
BigDecimal divisor)
检测数值d能否被divisor整除(即:余数为0)
|
Arith |
ceil()
将当前BigDecimal进行向上舍入到相邻的整数
|
static long |
ceil(double d)
向上取整,返回大于或等于指定数值的最小整数
|
static int |
compareTo(BigDecimal a,
BigDecimal b)
判断两个数值a和b的大小
|
static int |
compareTo(BigDecimal a,
double b)
判断两个数值a和b的大小
|
static int |
compareTo(BigDecimal a,
long b)
判断两个数值a和b的大小
|
static int |
compareTo(BigDecimal a,
String b)
判断两个数值a和b的大小
|
Arith |
divide(BigDecimal d)
商业除法运算
|
Arith |
divide(BigDecimal d,
int scale,
RoundingMode roundingMode)
商业除法运算
|
Arith |
divide(double d)
商业除法运算
|
static double |
divide(double a,
double b,
int scale)
商业除法运算(四舍五入)
|
Arith |
divide(double d,
int scale,
RoundingMode roundingMode)
商业除法运算
|
Arith |
divide(long d)
商业除法运算
|
Arith |
divide(long d,
int scale,
RoundingMode roundingMode)
商业除法运算
|
Arith |
divide(String d)
商业除法运算
|
Arith |
divide(String d,
int scale,
RoundingMode roundingMode)
商业除法运算
|
Arith |
divideRound(BigDecimal d,
int scale)
以四舍五入的舍入方式进行商业除法运算
|
Arith |
divideRound(double d,
int scale)
以四舍五入的舍入方式进行商业除法运算
|
Arith |
divideRound(long d,
int scale)
以四舍五入的舍入方式进行商业除法运算
|
Arith |
divideRound(String d,
int scale)
以四舍五入的舍入方式进行商业除法运算
|
double |
doubleValue()
转换为double值
|
double |
doubleValue(int scale)
转换为四舍五入精确到指定小数位的double值
|
static double |
even(double d,
int scale)
以
RoundingMode.HALF_EVEN 的方式使指定小数精确到指定的小数位数 |
float |
floatValue()
转换为float值
|
Arith |
floor()
将当前BigDecimal进行向下舍去到相邻的整数
|
static long |
floor(double d)
向下取整,返回小于或等于指定数值的最大整数
|
int |
intValue()
转换为int值
|
static boolean |
isIntegral(BigDecimal d)
检测指定的BigDecimal是否为整数值
|
long |
longValue()
转换为long值
|
Arith |
minus(BigDecimal d)
商业减法运算
|
Arith |
minus(double d)
商业减法运算
|
static double |
minus(double a,
double b)
商业减法运算
|
Arith |
minus(long d)
商业减法运算
|
Arith |
minus(String d)
商业减法运算
|
Arith |
multiply(BigDecimal d)
商业乘法运算
|
Arith |
multiply(double d)
商业乘法运算
|
static double |
multiply(double a,
double b)
商业乘法运算
|
static double |
multiply(double a,
double b,
int scale)
商业乘法运算(四舍五入)
|
static double |
multiply(double a,
double b,
int scale,
RoundingMode roundingMode)
商业乘法运算
|
static double |
multiply(double a,
double b,
long precision)
商业乘法运算(四舍五入)
注意:此方法的有效位数包含整数部分在内 将precision设为long类型只是为了重载的需要 |
Arith |
multiply(long d)
商业乘法运算
|
Arith |
multiply(String d)
商业乘法运算
|
static double |
round(double d,
int scale)
以四舍五入(
RoundingMode.HALF_UP)的方式使指定小数精确到指定的小数位数 |
Arith |
round(int newScale)
设置四舍五入的精度(即精确到的小数位数)
|
static double |
roundFast(double value,
int newScale)
设置四舍五入的精度(即精确到的小数位数)
注意:该方法底层直接根据需求自行计算,常规情况下比 round(int) 要快 10+倍,但目前尚处于实验性质(不过一般基本上没什么问题) |
static double |
scale(double d,
int scale,
RoundingMode mode)
以指定的舍入方式使指定小数精确到指定的小数位数
|
Arith |
setScale(int newScale,
RoundingMode roundingMode)
设置精度(即精确到的小数位数)
|
short |
shortValue()
转换为short值
|
BigDecimal |
toBigDecimal()
转换为BigDecimal
|
BigInteger |
toBigInteger()
转换为BigInteger
|
String |
toChineseString(boolean ignoreFractionalPart,
boolean upperCase)
输出中文形式的数值字符串,例如:"135000000"->"一亿三千五百万"
|
String |
toChineseUpperCase(boolean ignoreFractionalPart)
输出大写中文形式的数值字符串,例如:"135000000"->"壹亿叁千伍佰万"
|
String |
toMoneyUpperCase()
输出大写中文形式的用于金额(人民币)显示的数值字符串,例如:"135000000"->"壹亿叁千伍佰万元整"
|
String |
toString()
输出数值字符串
|
String |
toString(int scale)
输出以四舍五入模式保留指定小数位精度的数值字符串
|
static double |
truncate(double d,
int scale,
RoundingMode mode)
以指定舍入方式使指定小数精确到指定的小数位数
|
public static final BigDecimal ZERO
public static final BigDecimal ONE
public static final BigDecimal TEN
public static final BigDecimal HANDRED
public static final BigDecimal THOUSAND
public static final BigDecimal MYRIAD
public static final BigDecimal HANDRED_MILLION
protected BigDecimal value
public Arith(double d)
d - public Arith(String d)
d - public Arith(BigDecimal d)
d - public Arith(long d)
d - public Arith(int d)
d - public Arith(boolean d)
d - public Arith(Object d)
d - public Arith()
public Arith add(BigDecimal d)
d - 指定的加数public Arith add(double d)
d - 指定的加数public Arith add(long d)
d - 指定的加数public Arith minus(BigDecimal d)
d - 指定的减数public Arith minus(double d)
d - 指定的减数public Arith minus(long d)
d - 指定的减数public Arith multiply(BigDecimal d) throws ArithmeticException
d - 指定的乘数ArithmeticException - 如果无法除尽或除数为0则会抛出该异常,无法除尽时请使用Arith#divide(BigDecimal, int, RoundingMode)替代public Arith multiply(double d)
d - 指定的乘数public Arith multiply(long d)
d - 指定的乘数public Arith divide(BigDecimal d) throws ArithmeticException
d - 指定的除数ArithmeticException - 如果无法除尽或除数为0则会抛出该异常,无法除尽时请使用Arith#divide(BigDecimal, int, RoundingMode)替代public Arith divide(String d) throws ArithmeticException
d - 指定的除数ArithmeticException - 如果无法除尽或除数为0则会抛出该异常,无法除尽时请使用Arith#divide(String, int, RoundingMode)替代public Arith divide(double d)
d - 指定的除数ArithmeticException - 如果无法除尽或除数为0则会抛出该异常,无法除尽时请使用Arith#divide(double, int, RoundingMode)替代public Arith divide(long d)
d - 指定的除数ArithmeticException - 如果无法除尽或除数为0则会抛出该异常,无法除尽时请使用Arith#divide(long, int, RoundingMode)替代public Arith divide(BigDecimal d, int scale, RoundingMode roundingMode)
d - 指定的除数scale - 指定的精确位数roundingMode - 设置应用的舍入模式(四舍五入、向上舍入、向下舍去等)public Arith divide(String d, int scale, RoundingMode roundingMode)
d - 指定的除数scale - 指定的精确位数roundingMode - 设置应用的舍入模式(四舍五入、向上舍入、向下舍去等)public Arith divide(double d, int scale, RoundingMode roundingMode)
d - 指定的除数scale - 指定的精确位数roundingMode - 设置应用的舍入模式(四舍五入、向上舍入、向下舍去等)public Arith divide(long d, int scale, RoundingMode roundingMode)
d - 指定的除数scale - 指定的精确位数roundingMode - 设置应用的舍入模式(四舍五入、向上舍入、向下舍去等)public Arith divideRound(BigDecimal d, int scale)
d - 指定的除数scale - 指定的精确位数public Arith divideRound(String d, int scale)
d - 指定的除数scale - 指定的精确位数public Arith divideRound(double d, int scale)
d - 指定的除数scale - 指定的精确位数public Arith divideRound(long d, int scale)
d - 指定的除数scale - 指定的精确位数public Arith setScale(int newScale, RoundingMode roundingMode)
newScale - 指定的精确位数roundingMode - 设置应用的舍入模式(四舍五入、向上舍入、向下舍去等)public Arith round(int newScale)
newScale - 指定的精确位数public static final double roundFast(double value,
int newScale)
round(int) 要快 10+倍,但目前尚处于实验性质(不过一般基本上没什么问题)value - 指定的数值newScale - 指定的精确位数public Arith ceil()
public Arith floor()
public BigDecimal toBigDecimal()
public BigInteger toBigInteger()
public double doubleValue()
public double doubleValue(int scale)
public int intValue()
public long longValue()
public float floatValue()
public byte byteValue()
public short shortValue()
public static final double add(double a,
double b)
a - 加数1b - 加数2more - 更多的其他加数public static final double minus(double a,
double b)
a - 被减数b - 减数public static final double multiply(double a,
double b)
a - 乘数1b - 乘数2public static final double multiply(double a,
double b,
int scale,
RoundingMode roundingMode)
a - 乘数1b - 乘数2scale - 小数部分的精确位数舍入模式 - public static final double multiply(double a,
double b,
int scale)
a - 乘数1b - 乘数2scale - 小数部分的精确位数public static final double multiply(double a,
double b,
long precision)
a - 乘数1b - 乘数2precision - 包含整数部分的有效位数public static final double divide(double a,
double b,
int scale)
a - 被除数b - 除数scale - 小数精确度位数public static final double round(double d,
int scale)
RoundingMode.HALF_UP)的方式使指定小数精确到指定的小数位数d - 指定的小数scale - 指定的小数精确位数public static final double even(double d,
int scale)
RoundingMode.HALF_EVEN 的方式使指定小数精确到指定的小数位数d - 指定的小数scale - 指定的小数精确位数public static final double scale(double d,
int scale,
RoundingMode mode)
num - 指定的小数scale - 指定的小数精确位数public static final long ceil(double d)
d - 指定的数值public static final long floor(double d)
d - 指定的数值public static final double truncate(double d,
int scale,
RoundingMode mode)
d - 指定的小数scale - 指定的小数精确位数mode - 指定的舍入模式public static final int compareTo(BigDecimal a, BigDecimal b)
a - b - public static final int compareTo(BigDecimal a, double b)
a - b - public static final int compareTo(BigDecimal a, long b)
a - b - public static final int compareTo(BigDecimal a, String b)
a - b - public static final boolean isIntegral(BigDecimal d)
d - public static final boolean canDivideExactly(BigDecimal d, BigDecimal divisor)
d - 被除数divisor - 除数public String toString(int scale)
public String toChineseString(boolean ignoreFractionalPart, boolean upperCase)
ignoreFractionalPart - 是否忽略小数部分public String toChineseUpperCase(boolean ignoreFractionalPart)
ignoreFractionalPart - 是否忽略小数部分public String toMoneyUpperCase()
Copyright © 2020. All rights reserved.