Back to Geneos FAQ

How to round off a decimal number in JMX plugin without using Custom Format Masks?

This can be achieved with Custom Format Masks as discussed in another article. We are also providing an alternative method with arithmetic expressions here.

There was a known compatibility issue when using arithmetic expressions with newer Java versions (e.g. JDK 17 and above). Please make sure that you have Netprobe version GA6.7.0 and above (COL-11983). In this example, we are trying to capture version numbers from the MBeans under java.lang:type=Runtime. The values for ManagementSpecVersion and SpecVersion are 1.2 and 1.8 respectively in our case. Case 1: Round down a decimal number The original value can be represented as $1.SpecVersion. To round down the value, the logic is take the value and minus the remainder of itself divided by 1.

$1.SpecVersion - $1.SpecVersion % 1

Case 2: Round off to the nearest integer A trick is used here to add 0.5 to the original value, then perform the Round Down calculation as case 1. The result would effectively be rounding off to the nearest integer.

($1.SpecVersion + 0.5) - ($1.SpecVersion + 0.5) % 1

Below is the Active Console output showing the original and rounded values. Screenshot The sampler configuration in XML format has been attached as reference.

Further Reading Copied

["Geneos"] ["Geneos > Netprobe"] ["FAQ"]

Was this topic helpful?