How to convert an integer (int, Short, Long, Float, Double) to String

WmTransformationServices package also has a pile of services for various type conversions.

For Java services an easy trick is to just use concat to convert numeric types to string.

int a = 123;
String s = a+“”;

Another thing to keep in mind – avoid the use of float and double (and Float/Double wrappers) if accuracy is important. For most business integrations, it is important to get monetary values correct. There are various articles on the web describing the issues. And many discussions about speed and precision and such. Many folks refer to using rounding and truncating to address the issues with binary floating point arithmetic–but accumulated errors over several calculations can be a problem.

This means the *Floats services in pub.math are to be avoided. Using them has a high likelihood of being an issue at some point – and is usually one of the silent issues that no one can seem to figure out why reconciliation is off. For example:

image

Of course rounding would address this, by why should we need to round in this case? Just avoid using float/double to avoid the issue.

Another item to be aware of is how Integration Server handles JSON. By default, it uses native types. As we know, JSON is a string representation. So IS converts strings to native types and vice versa. This alone, depending upon the specific values and the JVM (to some degree) can introduce accuracy errors. Beware.

It is relatively easy to create your own services for arithmetic using BigDecimal within. It has its own set of pitfalls so be aware of those.

If anyone is curious about this, run pub.math:multiplyFloats with 3 and 13.2 as input. You’ll be surprised with the result.

1 Like