Skip to content

Martini Util Functions

The Util class in Martini provides a comprehensive set of functions for formatting numerical data types, such as double or long, into string representations. These functions are essential for developers looking to manipulate and display numeric data in Martini services or Groovy scripts.

Key Features

  • Number Formatting: Enables the conversion of numeric types to formatted string representations.
  • Precision Control: Offers the ability to specify the precision level, including the number of decimal places.
  • Versatility: Applicable in a variety of contexts within Martini, including services and Groovy-based scripting.

Usage Instructions

Accessing Util Functions

Util functions can be accessed and utilized in the following ways: - Via the Navigator: Locate the Util folder within the functions node of the Martini Navigator. Functions can be dragged into your service. - Through Content Assist: Activate content assist in your editor (usually with the . key) and type util.format. This will display the available functions and provide brief inline documentation.

Formatting Example in Groovy

To illustrate the usage of Util functions, consider a scenario where you need to format a double value in Groovy:

1
2
3
4
5
6
// Example of formatting a double value
double exampleValue = 12345.6789
String formattedValue = exampleValue.format('00000.00')

// The output will be '12345.68'
assert formattedValue.equals('12345.68')

In this example, the format function is used to convert a double value into a string with a specific format, demonstrating the control over decimal places and overall number formatting.

Practical Application Tips

  • Defining Format: When formatting a number, define the desired format string according to your requirements, such as '00000.00' for a fixed number of integer and decimal places.
  • Customizing Decimal Separator: You can customize the decimal separator if needed, adapting the format string accordingly.
  • Output Utilization: The formatted string can be used in subsequent steps of your service or script, such as for display purposes or logging.