# Apex - Division Calculation Result Is 0? (Expected Decimal Number, Does It Follow BIDMAS?)

Just a quick question.

I was trying to `System.debug()` a calculation I was doing:

``````(260 / (260 - 28)) - 1
``````

That should print something close to `0.12068965517241379310344827586207`.

But, my debugs were giving me 0. I was using the data type `Decimal`.

I tried to debug a comparison between `(260 / (260 - 28)) - 1` vs `(260 / (260 - 27)) - 1`, but the debug returned true, so it didn't seem like there were any hidden numbers after the 0 that debugs don't show or something.

I retried it, without using brackets, so I broke up the maths into:

``````Decimal upliftForHolidayProvisionPercent = 260 - 28;
Decimal upliftForHolidayProvisionPercentP2 = 260 / upliftForHolidayProvisionPercent;
Decimal upliftForHolidayProvisionPercentP3 = upliftForHolidayProvisionPercentP2 - 1;
System.debug(upliftForHolidayProvisionPercentP3);
``````

And that debug returned the expected value of `0.12068965517241379310344827586207` - it's the exact same calculation though.

Hence the question - is Apex unable to understand bracketed maths? It compiled all fine though, so I was wondering why it was giving me 0.

I am sorry, I haven't done more than a few Google searches, just curious but I have to keep working on this code ready for tomorrow!

• Apex follows normal precedence rules. The issue you have is that you are performing integer arithmetic. Try adding a ".0" to one or more of the values to cause floating point arithmetic to be applied. The split calculation worked because you used Decimal type, which caused floating point conversion to happen. Jul 5, 2022 at 19:46
– User
Jul 5, 2022 at 19:52

``````(260.0 / (260 - 28)) - 1