com.internationalnetwork.math
Class ConvertNumber

Object
  extended by com.internationalnetwork.math.ConvertNumber

public class ConvertNumber
extends Object

This class provides number conversion methods.


Field Summary
static String VERSION
          Version number of this Package (read-only).
 
Constructor Summary
ConvertNumber()
           
 
Method Summary
static String typeAlias(String num)
          Converts one of the following numeric data type keywords to its expected numeric value, while keeping it in String format.  This is useful for providing more flexibility to end-users in a number of places, including configuration files or user interfaces, by handling their string prior to converting it an actual primitive/native numeric data type.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final String VERSION
Version number of this Package (read-only).

See Also:
Constant Field Values
Constructor Detail

ConvertNumber

public ConvertNumber()
Method Detail

typeAlias

public static String typeAlias(String num)
Converts one of the following numeric data type keywords to its expected numeric value, while keeping it in String format.  This is useful for providing more flexibility to end-users in a number of places, including configuration files or user interfaces, by handling their string prior to converting it an actual primitive/native numeric data type.

If the keyword isn't found (and thus no conversion takes place), the original String is returned without modifications.  No exception is thrown.  The purpose of this method is not to eliminate all number format exceptions, but to provide a convenient way to express a few standard numbers through specialized text-based keywords.  The supported keywords are:


      -nybble..nybble   =                                       -8..7
        -byte..byte     =                                     -128..127
       -short..short    =                                   -32768..32767
         -int..int      =                              -2147483648..2147483647
        -long..long     =                     -9223372036854775808..9223372036854775807
    -verylong..verylong = -170141183460469231731687303715884105728..170141183460469231731687303715884105727
       -float..float    =                 -1.40129846432481707e-45..3.40282346638528860e+38
      -double..double   =                -4.94065645841246544e-324..1.79769313486231570e+308
    

You don't need to worry if a number is larger than your target data type because you still need to catch the appropriate exception(s).  If you specify a range, your users who prefer to use these keywords are likely to understand the effects of using out-of-range values anyway.

Internally, an optimized order of simple "if" statements is used to compare the supplied String, which is more efficient than using a HashMap which comes with more overhead due to additional calculations that really aren't needed for simple tasks such as this.

A special note of appreciation goes to Roedy Green for his work on accurately documenting the actual minimum and maximum values of the "float" and "double" primitives in an easy-to-read chart on his web site at:  http://mindprod.com/jgloss/primitive.html.

The Nybble and VeryLong types were added by Randolf Richardson.

Parameters:
num - The numeric string to convert
Returns:
String The [possibly] converted numeric value