Back to index

wims  3.65+svn20090927
Static Public Member Functions
fr.ove.utils.NumberUtils Class Reference

List of all members.

Static Public Member Functions

static boolean isNumber (String token)
 Analyzes a token and determines whether it is a number (integer or float) or not.
static boolean isFloat (String token)
 Analyzes the token and determines wheter it is an integer or a float.
static String formatDouble (String dValue)
 Formats the specified double value with two digits after decimal place.

Detailed Description

Author:
1999 DIRAT Laurent
Version:
2.0 28/06/1999

Definition at line 15 of file NumberUtils.java.


Member Function Documentation

static String fr.ove.utils.NumberUtils.formatDouble ( String  dValue) [inline, static]

Formats the specified double value with two digits after decimal place.

Parameters:
dValuethe value to format.

Definition at line 55 of file NumberUtils.java.

                                                     {
        NumberFormat form;
        form = NumberFormat.getInstance();//get local number format instance
        form.setMaximumFractionDigits(2);//set for 2 digits only after decimal place
        form.setMinimumFractionDigits(1);//set for 2 digits after decimal place
        form.setGroupingUsed(false);//no comma for thousands
        form.setMinimumIntegerDigits(1);//leading 0 if < 1

        try {
            return form.format((Double.valueOf(dValue)).doubleValue());
        } catch (Exception execp) {
             return dValue;
        }
    }

Here is the caller graph for this function:

static boolean fr.ove.utils.NumberUtils.isFloat ( String  token) [inline, static]

Analyzes the token and determines wheter it is an integer or a float.

We assume that the specified token is already a number.

Parameters:
tokenthe token to analyze.
Returns:
true if the token is a float. false if the token is an integer.

Definition at line 43 of file NumberUtils.java.

                                                {
        for (int i = 0; i < token.length(); i++)
            if (token.charAt(i) == '.')
                return true;
                
        return false;
    }
static boolean fr.ove.utils.NumberUtils.isNumber ( String  token) [inline, static]

Analyzes a token and determines whether it is a number (integer or float) or not.


If not, considers this token as a variable.

Parameters:
tokenthe token to anlazye.
Returns:
true if the token is a number. false otherwise.

Definition at line 24 of file NumberUtils.java.

                                                 {
        char oneChar;
        
        for (int i = 0; i < token.length(); i++) {
            oneChar = token.charAt(i);
            
            if (!Character.isDigit(oneChar) && (oneChar != '.'))
                return false;
        }
        return true;
    }

The documentation for this class was generated from the following file: