0

When I run the following code, it will return a 0. It should return 50.00.

System.Debug((100/200)*100); 

I'm certain this is a simple solution. But haven't been able to find out the reason why. I have also tried it with decimals i.e.

System.Debug((100.00/200.00)*100); 

0

1 Answer 1

1

The latter should work. When you divide an Integer by an Integer you get an Integer back which has the same value as Decimal.round(RoundingMode.DOWN).

system.assertEquals(0, 100/200);

However, when you divide decimals, you should get an exact value.

system.assertEquals(.5, 100.00/200.00);
1
  • I must of had a typo in my original code block. Thanks!
    – thinker
    Commented Dec 6, 2019 at 18:37

Not the answer you're looking for? Browse other questions tagged .