shh2.javasrc
Class Format

Object
  |
  +--Format

public class Format
extends Object

Formatting utilities.

Author:
Mark McConnell

Constructor Summary
Format()
           
 
Method Summary
static String round(float x, int dec_places)
          Given the float x, rounds it off to the nearest dec_places decimal places, if any.
static String roundToSigFig(float x, int sig_figs)
          Converts the number of significant figures (sig_figs) into the appropriate number of decimal places, then passes off the work to round(float, int).
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Format

public Format()
Method Detail

round

public static String round(float x,
                           int dec_places)
Given the float x, rounds it off to the nearest dec_places decimal places, if any. Examples:

WARNING: there will be errors if rounding x * 10^(dec_places) to the nearest integer overflows the int datatype.

Returns:
A String containing the rounded-off value.
Throws:
IllegalArgumentException - If dec_places is less than 0 (just because we haven't written that case).

roundToSigFig

public static String roundToSigFig(float x,
                                   int sig_figs)
Converts the number of significant figures (sig_figs) into the appropriate number of decimal places, then passes off the work to round(float, int).

The result is incorrect in some ways.