If you would like to upgrade to a newer long-term support version of Studio Pro, see Moving from Mendix Studio Pro 8 to 9.
Parse and Format Decimal Function Calls
Introduction
This document describes parsing and formatting decimal function calls. For details on all the pattern possibilities, see Class DecimalFormat.
parseDecimal
Parses a string value to a decimal value. Takes optional parameters for the format and default values.
Input Parameters
The input parameters are described in the table below:
Value | Type |
---|---|
Value to parse | String |
Format for the input value based on the Java library DecimalFormat (for more information, see Class DecimalFormat) |
String |
Default value (optional) | Decimal or empty |
Output
The output is described in the table below:
Value | Type |
---|---|
The output is a decimal value that matches the supplied string value. If the value cannot be parsed (meaning, it does not match the format parameter or contains illegal characters), the default value will be returned. If no default value is provided, an error occurs. | Decimal |
Example
The following examples demonstrate which output you get depending on input parameters:
parseDecimal('3.45')
returns3.45
parseDecimal('noDecimal', 5.05)
returns5.05
parseDecimal('noDecimal', empty)
returnsempty
parseDecimal('3,241.98', '#,###.##')
returns3241.98
formatDecimal
Converts a decimal value to a string value according to a specified format.
Input Parameters
The functionality of formatDecimal depends on whether it is used in a microflow or a nanoflow.
Input Parameters in Microflows
The input parameters are described in the table below:
Value | Type |
---|---|
Value to convert | Decimal |
Format for the result based on the Java library DecimalFormat (for details, see Class DecimalFormat) |
String |
Locale in which the results should be formatted (optional). For the more information on supported values, see forLanguageTag. When omitted, the user configured locale is used. | String |
Input Parameters in Nanoflows
In nanoflows, this function only takes a single parameter described below:
Value | Type |
---|---|
Value to convert | Decimal |
Output
The output is described in the table below:
Value | Type |
---|---|
A string representation of the decimal in the format specified by the format parameter. |
String |
Note that the exact output may depend on the Java version and user locale, depending on the passed format.
Microflow Examples
The examples below illustrate which value the expression returns:
-
If you use the following input:
formatDecimal(1234.56, '#,###.#')
the output is (depending on the language settings):
'1,234.5' or '1.234,5'
-
If you use the following input:
formatDecimal(1234.56, '¤ #,##0.00')
the output is (depending on language settings):
'€ 1.234,50' or '$ 1,234.50'
-
If you use the following input:
formatDecimal(0.56, '% ##0')
the output is
'% 56'
Nanoflow Examples
In a nanoflow, this will format the decimal using the format appropriate to the user’s locale.