类 NumberUtils
java.lang.Object
com.walker.infrastructure.utils.NumberUtils
Miscellaneous utility methods for number conversion and parsing.
Mainly for internal use within the framework; consider Jakarta's
Commons Lang for a more comprehensive suite of string utilities.
- 从以下版本开始:
- 1.1.2
- 作者:
- Juergen Hoeller, Rob Harrop
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static <T extends Number>
TconvertNumberToTargetClass(Number number, Class<T> targetClass) Convert the given number into an instance of the given target class.static <T extends Number>
TparseNumber(String text, Class<T> targetClass) Parse the given text into a number instance of the given target class, using the correspondingdecode/valueOfmethods.static <T extends Number>
TparseNumber(String text, Class<T> targetClass, NumberFormat numberFormat) Parse the given text into a number instance of the given target class, using the given NumberFormat.
-
构造器详细资料
-
NumberUtils
public NumberUtils()
-
-
方法详细资料
-
convertNumberToTargetClass
public static <T extends Number> T convertNumberToTargetClass(Number number, Class<T> targetClass) throws IllegalArgumentException Convert the given number into an instance of the given target class.- 参数:
number- the number to converttargetClass- the target class to convert to- 返回:
- the converted number
- 抛出:
IllegalArgumentException- if the target class is not supported (i.e. not a standard Number subclass as included in the JDK)- 另请参阅:
-
parseNumber
Parse the given text into a number instance of the given target class, using the correspondingdecode/valueOfmethods.Trims the input
Stringbefore 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 into- 返回:
- the parsed number
- 抛出:
IllegalArgumentException- if the target class is not supported (i.e. not a standard Number subclass as included in the JDK)- 另请参阅:
-
parseNumber
public static <T extends Number> T parseNumber(String text, Class<T> targetClass, NumberFormat numberFormat) Parse the given text into a number instance of the given target class, using the given NumberFormat. Trims the inputStringbefore attempting to parse the number.- 参数:
text- the text to converttargetClass- the target class to parse intonumberFormat- the NumberFormat to use for parsing (ifnull, this method falls back toparseNumber(String, Class))- 返回:
- the parsed number
- 抛出:
IllegalArgumentException- if the target class is not supported (i.e. not a standard Number subclass as included in the JDK)- 另请参阅:
-