Pub.math.absolutevalue rounding granularity?

I’ve found that it appears that, by default, pub.math.absoluteValue rounds its output to 3 decimal places, so the absolute value of 0.0047 would be returned as 0.005. Obviously, this is problematic, since nobody expects calculating the absolute value to actually alter any part of the value other than the sign. I’m seeing this in both 10.3 and 10.11.

Does anybody know if there’s an extended setting (or something else) that can control whether rounding is performed as part of the absolute value calculation, or at least control how many decimal places it rounds to? Or am I going to have to abandon this service and write my own replacement that works properly?

Hi @Andy_Simmons1,

As it appears this is how it’s designed and for now, you might want to write a replacement that would suffice your requirement. I would also recommend you raise a ticket with support for us to look into this more closely to arrive at a solution if there needs a correction.

HTH,
Sree

You may find the exchange at How to convert an integer (int, Short, Long, Float, Double) to String - #7 by John_Carter4 to be of interest.

It appears the absolute service (and possibly others) try to use BigDecimal to avoid the inherent inaccuracies of float/double but then subvert that effort by having an intermediate double type.

Likely need to follow the suggestion from @Sreekanth_Siddapur_Channakeshava to create your own replacement that avoids using float/double at any step. Here is simplistic code that is not as robust in terms of the input handling as the built-in service, but does not have a double in the mix.

		IDataCursor idc = pipeline.getCursor();
		String number = IDataUtil.getString(idc, "number");
		
		IDataUtil.put(idc, "positiveNumber", new java.math.BigDecimal(number).abs().toString());
		idc.destroy();		

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.