Parse and format float function calls

1 minute to read Download PDF Edit

See http://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html for all pattern possibilities.

parseFloat

Parses a String value to a Float value. Takes optional parameters for format and default value.

Input parameters

  • value to parse Type: String
  • pattern to match on (optional) Type: String
  • default value (optional) Type: Float

Output

A Float value that matches the input String value. If the value cannot be parsed (i.e. does not match the format parameter or contains illegal characters) the default value will be returned. If no default value was provided, an error occurs.

parseFloat('3.45')

returns:

3.45

with default value:

parseFloat('noFloat',5.05)

returns:

5.05

with format parameter:

parseFloat('$3.33', '$#.##')

returns:

3.33

formatFloat

Converts a Float value to a String value, according to a specified format.

Input parameters

  • value to convert Type: Float
  • format that the result should be in Type: String

Output

A String representation of the Float value, in the format specified by the ‘format’ parameter. Type: String

formatFloat(1234.56, '#,###.#')

returns:

'1,234.5'