Designer can't do basic maths?

What the hell?!

Hi @puszczyk,

The result of executing the following JavaScript code is “Result: 1998.9999999999998”:

var result = 19.99 * 100;
logger.info("Result: " + result);

And the result of executing the following JavaScript code is, as I assume, the result you are looking for, which is “Result: 1999.00”:

var result = (19.99 * 100).toFloat(2);
logger.info("Result: " + result);

Unfortunately I can’t tell you what the exact reason is why this happen. As far as I know is that it has something to do with how JavaScript treats these values. But to solve the issue you are facing you can use (record.fields.Price * 100).toFloat(2) instead.

1 Like

Welcome to the wonderful world of floating point math, where values are never exact unless you round them to the correct level of precision. This is why most software have a dedicated currency data type - including Connect, which you correctly used for your Price field. But then the custom JavaScript math code reverted it to its floating point primitive. I can show you Excel spreadsheets that do the same thing unless you use the round() function.

Long story short, Marten’s answer is correct, the result needs to be rounded to two decimals.

1 Like