OBOE: Need help understanding, possible type conversion issue.

lamez:
...
Right, it did not give me the expected output, but why?
...

If you really want to know...

Decimal numbers are powers of 10, your "ABC" numbers are powers of 26 and binary are powers of 2. For straightforward integers, each base can represent the number exactly. But this is not the case for real numbers.

The decimal calculation 1/10 is exactly 0.1 whereas 1/3 is an approximation: 0.333333333 etc. The digits after the decimal point represent 1/10th, 1/100th and so on. In base 3 the calculation "1"/"101" is exactly "0.1" i.e one third.

We usually use floating point numbers to represent Decimal numbers, but the internal calculation is in binary, using binary fractions. so

Decimal 1 / 10 is Binary "1" / "1010" which is (according to this website: Decimal/Binary Converter - Exploring Binary)

"0.00011001100110011001100110011"

and converting that back to Decimal gives you:

0.0999999999999943156581139191

Even if the calculation looks like it should only involve integers, the floating point routines will introduce tiny binary fractional bits. So, whenever you can - avoid floating point in code.

Even if you really want a couple of decimal places, you can still do that in integers as 'fixed point' e.g.

// 5/4 a 2-place fixed point
long int q=5;
long int d=4;
long int integer, fraction;

  integer= (q*100) / d;     
  fraction= integer % 100;
  integer= integer / 100;
  Serial.print(integer);Serial.print(".");Serial.println(fraction);
  
}

Yours,
TonyWilk