user87768: i want to ask, how to get correct float value from uint32_t or long variable is devided by 10??
long var3 = 1139399025;
int a = 3;
int b = 10;
void setup() {
  Serial.begin(9600);
  Serial.println((float)a/b,2);
  Serial.println((float)var3/b,2);
}
void loop() {
}

result
0.3
113939904.00

it give 113939904.00 instead of 113939902.50, plase how to fix that?

user7508: 1139399025 is not a floating point number: the largest odd integer that
can be exactly represented as a float is
224 − 1 = 16777215. Then, when var3 is
cast to float, it gets rounded to the closest float, which
is 1139399040. This is quite a small error, especially considering
that, in this range, only multiples of 128 can be exactly
represented as floats.
Dividing 1139399040 by 10 gives 113939904, which happens to be a float.
The floating point division gives then the exact result, which is what
gets printed. Indeed, floating point operations do not always give
inexact results: sometimes they are exact. However, unless you know what
you are doing, exact results only happen by luck. In general, expect
each floating point operation to make a relative rounding error in the
range of 10−7.
A highly recommended read: What Every Programmer Should Know About
Floating-Point Arithmetic.
Edit: If you want to print the value of an integer divided by 10,
you can divide the number using Euclidean division. Print the
quotient, then the decimal point, then the remainder:
Serial.print(var3 / 10);  // quotient
Serial.print('.');
Serial.println(var3 % 10);  // remainder

As these are all integer operations, there is no rounding error
involved. Obviously this trick doesn't work for arbitrary divisors.

87768: <p>i want to ask, how to get correct float value from uint32_t or long variable is devided by 10??</p>
<pre><code>long var3 = 1139399025;
int a = 3;
int b = 10;
void setup() {
  Serial.begin(9600);
  Serial.println((float)a/b,2);
  Serial.println((float)var3/b,2);
}
void loop() {
}
</code></pre>
<p>result</p>
<pre><code>0.3
113939904.00
</code></pre>
<p>it give 113939904.00 instead of 113939902.50, plase how to fix that?</p>
 7508: <p>1139399025 is not a floating point number: the largest odd integer that
can be exactly represented as a <code>float</code> is
2<sup>24</sup> − 1 = 16777215. Then, when <code>var3</code> is
cast to <code>float</code>, it gets rounded to the closest float, which
is 1139399040. This is quite a small error, especially considering
that, in this range, only multiples of 128 can be exactly
represented as floats.</p>
<p>Dividing 1139399040 by 10 gives 113939904, which happens to be a float.
The floating point division gives then the <em>exact</em> result, which is what
gets printed. Indeed, floating point operations do not always give
inexact results: sometimes they are exact. However, unless you know what
you are doing, exact results only happen by luck. In general, expect
each floating point operation to make a <em>relative</em> rounding error in the
range of 10<sup>−7</sup>.</p>
<p>A highly recommended read: <a href="https://floating-point-gui.de/" rel="nofollow noreferrer">What Every Programmer Should Know About
Floating-Point Arithmetic</a>.</p>
<p><strong>Edit</strong>: If you want to print the value of an integer divided by 10,
you can divide the number using <a href="https://en.wikipedia.org/wiki/Euclidean_division" rel="nofollow noreferrer">Euclidean division</a>. Print the
quotient, then the decimal point, then the remainder:</p>
<pre class="lang-cpp prettyprint-override"><code>Serial.print(var3 / 10);  // quotient
Serial.print('.');
Serial.println(var3 % 10);  // remainder
</code></pre>
<p>As these are all integer operations, there is no rounding error
involved. Obviously this trick doesn't work for arbitrary divisors.</p>
