Looking for a calculation explanation.

Hi guys, I was debugging my program because I thought some values weren’t right. So I started very simple outputting some calculations using divide and modulus.

Here are the results:

2 / 10 = 0,2

2 % 10 = 2 // Shouldn’t the answer be 0?

1 / 3 = ~ 0,3333333333333333333333333333

1 % 3 = 1 // Shouldn’t the answer be ~ 0,0000000000000000000000000001

I’m confused about the % calculations. I always thought it would output the “rest” part of the calculation. So since 2 divided by 10 is 0,2 exactly there shouldn’t be a rest. But the rest is 2. And if I do 1 / 3, there’s a very small number that’s left, but it shouldn’t be 1 right? I’m using decimals for my calculations.

I’m hoping someone could explain me what I’m doing wrong or what’s happening.

submitted by /u/Royy212
[link] [comments]

Leave a Reply