user27204: This probably sounds dumb, but I am not getting any clear answer for this. What data type allows a reasonable amount of decimals?

user7508: If you need to represent numbers that are not integers, the simplest
solution is to use floating point variables, also known as “floats”. A
float is declared with the float keyword. A numeric constant is
automatically a float if it has a decimal point :

42 is an integer (int type)
42.0 is a float

If you combine an int and a float in an arithmetic operation, the int is
implicitly promoted to float, and the result is a float.
A float gives you a precision of 24 significant bits. “Significant”
means that we are counting both the bits before and after the binary
point. Then, a small number will have many fractional bits, whereas a
large number will have only a few, and any number larger than
223 = 8388608 will have no fractional bits at all.
This precision is almost always better that 7 significant decimals and
worse than 8 significant decimals. For example, the following two
numbers are consecutive: any computation that yields a result in
between them will be rounded to either of them (usually the closest):
    binary (24 bits)          decimal
101010.000000000000000000  42.0
101010.000000000000000001  42.000003814697265625

The issue with floats is that they are expensive. Unlike a desktop
computer, the Trinket has no hardware support for floats (it's an
ATtiny: it doesn't even have a hardware multiplier!). Then every
computation is done by software. Even the simplest things, like adding
two numbers, can take quite a few CPU cycles and a lot of flash space.
That's why on very small devices people sometimes prefer fixed point
arithmetic. In a nutshell, fixed point is all about choosing appropriate
units of measurement in order to achieve the required precision using
only integers. For example, the ADC converter in the Trinket gives you
the voltage readings in units of
5 V ÷ 1024 = 4.8828125 mV

That unit may seem unpractical, but it allows a reasonable precision
using only integers. If you can avoid converting to volts, you will be
able to write integer-only code which is smaller and faster.
I would suggest you first try using floats, as it's the simplest
solution. If that leads to code with is either too large or too slow,
then try to rewrite with fixed-point (i.e. integer only) arithmetic.

27204: <p>This probably sounds dumb, but I am not getting any clear answer for this. What data type allows a reasonable amount of decimals?</p>
 7508: <p>If you need to represent numbers that are not integers, the simplest
solution is to use floating point variables, also known as “floats”. A
float is declared with the <code>float</code> keyword. A numeric constant is
automatically a float if it has a decimal point :</p>

<ul>
<li><code>42</code> is an integer (<code>int</code> type)</li>
<li><code>42.0</code> is a float</li>
</ul>

<p>If you combine an int and a float in an arithmetic operation, the int is
implicitly promoted to float, and the result is a float.</p>

<p>A float gives you a precision of 24 <em>significant bits</em>. “Significant”
means that we are counting both the bits <em>before</em> and <em>after</em> the binary
point. Then, a small number will have many fractional bits, whereas a
large number will have only a few, and any number larger than
2<sup>23</sup> = 8388608 will have <em>no</em> fractional bits at all.</p>

<p>This precision is almost always better that 7 significant decimals and
worse than 8 significant decimals. For example, the following two
numbers are consecutive: any computation that yields a result <em>in
between</em> them will be rounded to either of them (usually the closest):</p>

<pre><code>    binary (24 bits)          decimal
101010.000000000000000000  42.0
101010.000000000000000001  42.000003814697265625
</code></pre>

<p>The issue with floats is that they are expensive. Unlike a desktop
computer, the Trinket has no hardware support for floats (it's an
ATtiny: it doesn't even have a hardware multiplier!). Then every
computation is done by software. Even the simplest things, like adding
two numbers, can take quite a few CPU cycles and <em>a lot</em> of flash space.
That's why on very small devices people sometimes prefer <em>fixed point</em>
arithmetic. In a nutshell, fixed point is all about choosing appropriate
units of measurement in order to achieve the required precision using
only integers. For example, the ADC converter in the Trinket gives you
the voltage readings in units of</p>

<pre><code>5 V ÷ 1024 = 4.8828125 mV
</code></pre>

<p>That unit may seem unpractical, but it allows a reasonable precision
using only integers. If you can avoid converting to volts, you will be
able to write integer-only code which is smaller and faster.</p>

<p>I would suggest you first try using floats, as it's the simplest
solution. If that leads to code with is either too large or too slow,
then try to rewrite with fixed-point (i.e. integer only) arithmetic.</p>
