uk.ac.starlink.ttools.func
Class Formats

java.lang.Object
  extended by uk.ac.starlink.ttools.func.Formats

public class Formats
extends Object

Functions for formatting numeric values.

Since:
2 Sep 2004
Author:
Mark Taylor (Starlink)

Method Summary
static String formatDecimal(double value, int dp)
          Turns a floating point value into a string with a given number of decimal places using standard settings.
static String formatDecimal(double value, String format)
          Turns a floating point value into a formatted string using standard settings.
static String formatDecimalLocal(double value, int dp)
          Turns a floating point value into a string using current locale settings.
static String formatDecimalLocal(double value, String format)
          Turns a floating point value into a formatted string using current locale settings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

formatDecimal

public static String formatDecimal(double value,
                                   int dp)
Turns a floating point value into a string with a given number of decimal places using standard settings.

Parameters:
value - value to format
dp - number of decimal places (digits after the decmal point)
Returns:
formatted string
Examples:
formatDecimal(PI,0) = "3.", formatDecimal(0,10) = ".0000000000", formatDecimal(E*10,3) = "27.183"

formatDecimalLocal

public static String formatDecimalLocal(double value,
                                        int dp)
Turns a floating point value into a string using current locale settings. For instance if language is set to French, decimal points will be represented as a comma "," instead of a full stop ".". Otherwise behaves the same as the corresponding formatDecimal function.

Parameters:
value - value to format
dp - number of decimal places (digits after the decmal point)
Returns:
formatted string
Examples:
formatDecimal(PI,0) = "3,", formatDecimal(0,10) = ",0000000000", formatDecimal(E*10,3) = "27,183"

formatDecimal

public static String formatDecimal(double value,
                                   String format)
Turns a floating point value into a formatted string using standard settings. The format string is as defined by Java's java.text.DecimalFormat class.

Parameters:
value - value to format
format - format specifier
Returns:
formatted string
Examples:
formatDecimal(99, "#.000") = "99.000", formatDecimal(PI, "+0.##;-0.##") = "+3.14"

formatDecimalLocal

public static String formatDecimalLocal(double value,
                                        String format)
Turns a floating point value into a formatted string using current locale settings. For instance if language is set to French, decimal points will be represented as a comma "," instead of a full stop ".". Otherwise behaves the same as the corresponding formatDecimal function.

Parameters:
value - value to format
format - format specifier
Returns:
formatted string
Examples:
formatDecimal(99, "#.000") = "99,000", formatDecimal(PI, "+0.##;-0.##") = "+3,14"


Copyright © 2009 Central Laboratory of the Research Councils. All Rights Reserved.