Bug? Error? Mistake? Who Knows

Hello there, so a customer of us reported an error on an application because something that must be zero, for some reasons (that I don’t really understand) have a value, so when we debug the code found something pretty strange, just take a look.

As you can notice on that table there’s a script that do some simple calculations, X = A - B - C , in fact in the first image I made the calculation a string for debug purposes, but when let the field do the calculation something very strange happened:

So any suggestion?? Or am I just crazy?

Thanks in advance.

Can you show your code where are your formulas?

Sure, but it’s very simple, that’s why I don’t know what is happening.

image

The variable $suma is not a field, use {suma} ?

Yes, I tried both, with the same result, I don’t know what else to change.

How you get $suma variable?
validete if $suma is null

If you’re calculating fields make sure they’re the right datatypes and not string. And if you’re still facing issue try to do something like this:

$num1 = 13.29; // Put your fields here
$num2 = 9.88; // Put your fields here
$num3 = 3.4; // Put your fields here

(float)$result = (float)$num1 - (float)$num2 - (float)$num3;

{credito} = $result;

Well i found that for some reason, whenever you have a very large decimal number, for example 0.000096, the cell become 9.6, a very strange behavior, in my example the value “-1.33” was in fact -0.0000133, despite the fact that is rounded

That’s so strange indeed. It’s good that you’ve figure it out at the end. Better to have it rounded before inserting it into the DB depends on your use case. For myself, I always rounded 2 decimals for my financial related apps.