public class NumberKits extends Object
| 构造器和说明 |
|---|
NumberKits() |
| 限定符和类型 | 方法和说明 |
|---|---|
static <T extends Number> |
convertNumberToTargetClass(Number number,
Class<T> targetClass)
将给定的数字转换为给定目标类的实例
|
static boolean |
isHexNumber(String value)
判断字符串是否16进制
|
static boolean |
isNumber(String str)
判断字符串是否合法数字
|
static <T extends Number> |
parseNumber(Object val,
Class<T> targetClass)
Parse the given
val into a Number instance of the given
target class, the default value is returned if an error occurs. |
static <T extends Number> |
parseNumber(Object val,
Class<T> targetClass,
T defaultValue)
Parse the given
val into a Number instance of the given
target class, the default value is returned if an error occurs. |
static <T extends Number> |
parseNumber(String text,
Class<T> targetClass)
Parse the given
text into a Number instance of the given
target class, using the corresponding decode / valueOf method. |
static BigDecimal |
round(Number number,
int scale,
RoundingMode roundingMode)
保留固定位数小数
例如保留四位小数:123.456789 =》 123.4567 |
static BigDecimal |
round(String number,
int scale,
RoundingMode roundingMode)
保留固定位数小数
例如保留四位小数:123.456789 =》 123.4567 |
public static boolean isNumber(String str)
public static boolean isHexNumber(String value)
public static BigDecimal round(Number number, int scale, RoundingMode roundingMode)
number - 数字值scale - 保留小数位数,如果传入小于0,则默认0roundingMode - 保留小数的模式 RoundingMode,如果传入null则默认四舍五入public static BigDecimal round(String number, int scale, RoundingMode roundingMode)
number - 数字值scale - 保留小数位数,如果传入小于0,则默认0roundingMode - 保留小数的模式 RoundingMode,如果传入null则默认四舍五入public static <T extends Number> T convertNumberToTargetClass(Number number, Class<T> targetClass) throws IllegalArgumentException
number - 将要转换的数字targetClass - 目标类IllegalArgumentException - if the target class is not supported
(i.e. not a standard Number subclass as included in the JDK)Byte,
Short,
Integer,
Long,
BigInteger,
Float,
Double,
BigDecimalpublic static <T extends Number> T parseNumber(String text, Class<T> targetClass)
text into a Number instance of the given
target class, using the corresponding decode / valueOf method.
Trims the input String before attempting to parse the number.
Supports numbers in hex format (with leading "0x", "0X", or "#") as well.
text - the text to converttargetClass - the target class to parse intoIllegalArgumentException - if the target class is not supported
(i.e. not a standard Number subclass as included in the JDK)Byte.decode(java.lang.String),
Short.decode(java.lang.String),
Integer.decode(java.lang.String),
Long.decode(java.lang.String),
decodeBigInteger(String),
Float.valueOf(java.lang.String),
Double.valueOf(java.lang.String),
BigDecimal.BigDecimal(String)public static <T extends Number> T parseNumber(Object val, Class<T> targetClass, T defaultValue)
val into a Number instance of the given
target class, the default value is returned if an error occurs.
Trims the input Object before attempting to parse the number.
Supports numbers in hex format (with leading "0x", "0X", or "#") as well.
val - an object to converttargetClass - the target class to parse intodefaultValue - an default valueIllegalArgumentException - if the target class is not supported
(i.e. not a standard Number subclass as included in the JDK)Byte.decode(java.lang.String),
Short.decode(java.lang.String),
Integer.decode(java.lang.String),
Long.decode(java.lang.String),
decodeBigInteger(String),
Float.valueOf(java.lang.String),
Double.valueOf(java.lang.String),
BigDecimal.BigDecimal(String)public static <T extends Number> T parseNumber(Object val, Class<T> targetClass)
val into a Number instance of the given
target class, the default value is returned if an error occurs.
Trims the input Object before attempting to parse the number.
Supports numbers in hex format (with leading "0x", "0X", or "#") as well.
val - an object to converttargetClass - the target class to parse intoIllegalArgumentException - if the target class is not supported
(i.e. not a standard Number subclass as included in the JDK)Byte.decode(java.lang.String),
Short.decode(java.lang.String),
Integer.decode(java.lang.String),
Long.decode(java.lang.String),
decodeBigInteger(String),
Float.valueOf(java.lang.String),
Double.valueOf(java.lang.String),
BigDecimal.BigDecimal(String)Copyright © 2020. All rights reserved.