Package org.kissweb

Class NumberFormat

java.lang.Object
org.kissweb.NumberFormat

public class NumberFormat extends Object
Advanced method for formatting numbers.
  • Constructor Details

    • NumberFormat

      public NumberFormat()
  • Method Details

    • Formatb

      public static String Formatb(double num, int base, String msk, int wth, int dp)
      Numeric formatter. Takes a double and converts it to a nicely formatted String in a specified number base.
      Parameters:
      num - number to be formatted
      base - numeric base (like base 2 = binary, 16=hex...)
      msk - format mask - any combination of the following:
      • B = blank if zero
      • C = add commas
      • L = left justify number
      • P = put parentheses around negative numbers
      • Z = zero fill
      • D = floating dollar sign
      • U = uppercase letters in conversion
      • R = add a percent sign to the end of the number
      wth - total field width (0 means auto)
      dp - number of decimal places (-1 means auto)
      Returns:
      the formatted String

      example:

      String r = Formatb(-12345.348, 10, "CP", 12, 2);

      result in r:   "(12,345.35)"

      See Also:
    • Format

      public static String Format(double num, String msk, int wth, int dp)
      Numeric formatter. Takes a double and converts it to a nicely formatted String (for number in base 10).
      Parameters:
      num - number to be formatted
      msk - format mask - any combination of the following:
      • B = blank if zero
      • C = add commas
      • L = left justify number
      • P = put parentheses around negative numbers
      • Z = zero fill
      • D = floating dollar sign
      • U = uppercase letters in conversion
      • R = add a percent sign to the end of the number
      wth - total field width (0 means auto)
      dp - number of decimal places (-1 means auto)
      Returns:
      the formatted String

      example:

      String r = Format(-12345.348, "CP", 12, 2);

      result in r:   "(12,345.35)"

      See Also:
    • main

      public static void main(String[] argv)
      Test function.
      Parameters:
      argv -