ml.shifu.guagua.util
类 NumberFormatUtils

java.lang.Object
  继承者 ml.shifu.guagua.util.NumberFormatUtils

public final class NumberFormatUtils
extends Object

Util class to parse int, long or any other type.


方法摘要
static double getDouble(String str)
          Parse string object to double type.
static double getDouble(String str, boolean required)
          Parse string object to double type.
static double getDouble(String str, boolean required, double defaultValue)
          Parse string object to double type.
static double getDouble(String str, double defaultValue)
          Parse string object to double type.
static int getInt(String str)
          Parse string object to int type.
static int getInt(String str, boolean required)
          Parse string object to int type.
static int getInt(String str, boolean required, int defaultValue)
          Parse string object to int type.
static int getInt(String str, int defaultValue)
          Parse string object to int type.
static long getLong(String str)
          Parse string object to long type.
static long getLong(String str, boolean required)
          Parse string object to long type.
static long getLong(String str, boolean required, long defaultValue)
          Parse string object to long type.
static long getLong(String str, long defaultValue)
          Parse string object to long type.
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

方法详细信息

getInt

public static int getInt(String str,
                         int defaultValue)
Parse string object to int type.

参数:
str - string needed to be parsed
defaultValue - default value

getInt

public static int getInt(String str)
Parse string object to int type. If invalid format, use 0 to replace.

参数:
str - string needed to be parsed

getInt

public static int getInt(String str,
                         boolean required)
Parse string object to int type.

参数:
str - string needed to be parsed
required - if required, should be parsed successfully without default value to replace; else use 0 as default value.
抛出:
Exception - if invalid format with required set 'true'

getInt

public static int getInt(String str,
                         boolean required,
                         int defaultValue)
Parse string object to int type.

参数:
str - string needed to be parsed
required - if required, should be parsed successfully without default value to replace; else use default value.
defaultValue - default value
抛出:
IllegalArgumentException - if invalid format with required set 'true'

getLong

public static long getLong(String str,
                           long defaultValue)
Parse string object to long type.

参数:
str - string needed to be parsed
defaultValue - default value

getLong

public static long getLong(String str)
Parse string object to long type. If invalid format, use 0 to replace.

参数:
str - string needed to be parsed

getLong

public static long getLong(String str,
                           boolean required)
Parse string object to long type. If invalid format, use 0 to replace.

参数:
str - string needed to be parsed
required - if required, should be parsed successfully without default value to replace
抛出:
IllegalArgumentException - if invalid format with required set 'true'

getLong

public static long getLong(String str,
                           boolean required,
                           long defaultValue)
Parse string object to long type.

参数:
str - string needed to be parsed
required - if required, should be parsed successfully without default value to replace; else use default value.
defaultValue - default value
抛出:
Exception - if invalid format with required set 'true'

getDouble

public static double getDouble(String str,
                               double defaultValue)
Parse string object to double type.

参数:
str - string needed to be parsed
defaultValue - default value

getDouble

public static double getDouble(String str)
Parse string object to double type. If invalid format, use 0 to replace.

参数:
str - string needed to be parsed

getDouble

public static double getDouble(String str,
                               boolean required)
Parse string object to double type. If invalid format, use 0 to replace.

参数:
str - string needed to be parsed
required - if required, should be parsed successfully without default value to replace
抛出:
Exception - if invalid format with required set 'true'

getDouble

public static double getDouble(String str,
                               boolean required,
                               double defaultValue)
Parse string object to double type.

参数:
str - string needed to be parsed
required - if required, should be parsed successfully without default value to replace; else use default value.
defaultValue - default value
抛出:
IllegalArgumentException - if invalid format with required set 'true'


Copyright © 2014. All Rights Reserved.