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 |
|
Example 2: String to Long Conversion
1 2 |
|
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:
-
Function Selection: Choose a formatting function that aligns with the required formatting pattern.
-
Input Specification: Provide a floating-point number with the desired precision as input to the function.
-
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
#.##
. -
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.
-
Expected Outcome: The service, once executed, will output the formatted number, ensuring it adheres to the specified decimal place formatting.