Skip to content

Martini Number Functions

The Number class in Martini integrates a series of robust functions for handling numerical data, such as conversion and formatting. These functions are based on the Apache Commons org.apache.commons.lang3.math.NumberUtils class and are designed to be used in both service creation and Groovy scripting.

Usage in Groovy

The Number functions are directly applicable in Groovy, facilitating various numerical operations. Here are a couple of examples illustrating their usage:

Example 1: Number Formatting

1
2
// Formatting a floating-point number using a custom pattern
assert 3.14159265.format('000.000').equals('003.142')

Example 2: String to Long Conversion

1
2
// Converting a string to its long equivalent
assert '77345993'.toLong() == 77345993L

Integrating Number Functions in Services

Finding Number Functions

In the Martini platform, Number functions are located under the "functions" node in the navigator, specifically in the "number" folder. These functions can be utilized in your services through direct selection or by employing content assist with the keyword "number."

Function Identification

Each function within the Number class is prefixed with "number" for straightforward identification and application.

Utilizing Number Functions in Services

Scenario: Formatting Floating-Point Numbers

Objective: Implement a function to format a floating-point number to a specific number of decimal places.

Procedure:

  1. Function Selection: Choose a formatting function that aligns with the required formatting pattern.

  2. Input Specification: Provide a floating-point number with the desired precision as input to the function.

  3. Format Definition: Define the formatting pattern using the pound sign '#' in the format input property. For instance, to achieve two decimal places, use the pattern #.##.

  4. Output Handling: The function processes the input and returns a string formatted as specified. This output should be mapped to an appropriate variable in your service.

  5. Expected Outcome: The service, once executed, will output the formatted number, ensuring it adheres to the specified decimal place formatting.