Solve problems related to calculations with decimals with the Toolbox plugin

Hi,

On several occasions, I’ve encountered a result problem with the Toolbox plugin, probably because in France (as in other countries), we use the comma to separate whole numbers from their decimals and not the period. It seems to me that another user had encountered the same problem, but I couldn’t find the post.

Here’s the problem:

  1. On an empty page, I place 2 inputs (A and B) whose Content format is Decimal and whose Decimal place is 2:

  2. I then place an Expression element (Expression A) whose Expression is Input A's value + Input B's value and Result type is number:

  3. Finally, I add a text element that simply takes the result of the expression, i.e. Expression A's value:

The result is that if I write 10 in input A and 30 in input B, everything’s fine.
But if I write 10,25 and 30,45, I end up with 7, which is only the decimal of the result I should have had (40,7):
4

Of course, for such a simple calculation, a text element would suffice, but when I needed to use this plugin, it was for more complex calculations requiring several steps, and parentheses in calculations are still a beta feature.

So here’s the solution I used:

  1. For the Expression element, I add formatting, which gives Input A's value + Input B's value:formatted as 1028.58 where we leave the parameters as they are:

  2. For the text element, we also add a formatting where we choose 2 as Decimal place and the comma as Decimal separator. You can also choose Space as Thousand separator. This gives: Expression A's value:formatted as 1028,58:

The result is now 40,70.

It’s a little tip, but hope this helps :blush:

3 Likes

This occurs for any use of numbers across the app where the language is one that uses commas. So, for example, if you have an API call that uses a number, this will break when the language is set, for example, to Dutch (because 8.359 would become 8,359 which breaks the API call). For this reason, if the app is multilingual, it’s important to use :formatted as with decimal where necessary to avoid issues.

2 Likes