public class NumberUtils extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static boolean |
isDigits(String str)
Checks whether the
String contains only
digit characters. |
static double |
toDouble(String str,
double defaultValue)
Convert a
String to a double, returning a
default value if the conversion fails. |
static float |
toFloat(String str)
Convert a
String to a float, returning
0.0f if the conversion fails. |
static float |
toFloat(String str,
float defaultValue)
Convert a
String to a float, returning a
default value if the conversion fails. |
static int |
toInt(String str)
Convert a
String to an int, returning
zero if the conversion fails. |
static int |
toInt(String str,
int defaultValue)
Convert a
String to an int, returning a
default value if the conversion fails. |
static long |
toLong(String str,
long defaultValue)
Convert a
String to a long, returning a
default value if the conversion fails. |
public static int toInt(String str)
String to an int, returning
zero if the conversion fails.str - the string to convert, may be nullzero if
conversion failspublic static int toInt(String str, int defaultValue)
String to an int, returning a
default value if the conversion fails.str - the string to convert, may be nulldefaultValue - the default valuepublic static long toLong(String str, long defaultValue)
String to a long, returning a
default value if the conversion fails.str - the string to convert, may be nulldefaultValue - the default valuepublic static double toDouble(String str, double defaultValue)
String to a double, returning a
default value if the conversion fails.str - the string to convert, may be nulldefaultValue - the default valuepublic static boolean isDigits(String str)
String contains only
digit characters.str - the String to checktrue if str contains only unicode numericpublic static float toFloat(String str)
String to a float, returning
0.0f if the conversion fails.str - the string to convert, may be null0.0f
if conversion failspublic static float toFloat(String str, float defaultValue)
String to a float, returning a
default value if the conversion fails.str - the string to convert, may be nulldefaultValue - the default valueCopyright © 2018–2024 Alibaba Group. All rights reserved.