bcds.tools
Class NumberFmt<K,V>

java.lang.Object
  extended by bcds.tools.NumberFmt<K,V>

public class NumberFmt<K,V>
extends java.lang.Object

Formats a Number as a string, using the most simple (human) representation possible. For example, if double variable contains the value 12345.0, produces the string "12345". In this class, "integer" means any numeric value that "fits" into a long. Floating-point numbers are "printed" with the current locale.

Author:
Juan Segovia S.

Constructor Summary
NumberFmt()
          Default constructor.
NumberFmt(java.lang.String float_fmt)
          Creates a new instance that will format non-"integer" values with the format given in float_fmt, which must be a valid format specifier for String.format.
 
Method Summary
static java.lang.String asString(java.lang.Number n)
          Returns a string corresponding to the number n formatted using the default format specifier.
 java.lang.String format(java.lang.Number n)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumberFmt

public NumberFmt()
Default constructor. An non-"integer" value will be formated with 6 decimal digits.


NumberFmt

public NumberFmt(java.lang.String float_fmt)
Creates a new instance that will format non-"integer" values with the format given in float_fmt, which must be a valid format specifier for String.format.

Method Detail

format

public java.lang.String format(java.lang.Number n)

asString

public static java.lang.String asString(java.lang.Number n)
Returns a string corresponding to the number n formatted using the default format specifier. It is equivalent to:
    String z = new NumberFmt().format(some_value);
 
but the object used internally is instantiated only once. This method's name should have been format, but there is already a non-static method by that name.