# Accuracy loss while converting from int to float

**URL:** <https://forum.arduino.cc/t/accuracy-loss-while-converting-from-int-to-float/1425063>\
**Category:** Programming\
**Created:** [January 13, 2026, 10:52am UTC](https://forum.arduino.cc/t/accuracy-loss-while-converting-from-int-to-float/1425063 "2026-01-13T10:52:56Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ardubit](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ardubit/32/264049_2.png) [@Ardubit](https://forum.arduino.cc/u/Ardubit)\
**Post date:** [January 13, 2026, 10:52am UTC](https://forum.arduino.cc/t/accuracy-loss-while-converting-from-int-to-float/1425063/1 "2026-01-13T10:52:57Z")

</div>

I am reading a value of 9375 from EEPROM stored as an INT.

Then I am casting it to a float variable and dividing it with 1000000. The value I expect to get is 0,009375. But what i get is 0.01 after a round off. My process that uses this value gets messed up due to the rounding off … What am i doing wrong ??

```cpp
EEPROM.get ( eeAddress, eepromVal) ;
Serial.println(eepromVal); // Reads 9375. The correct value
voltPerScan = float(eepromVal) / 1000000 ; 
Serial.println(voltPerScan); // Reads 0.01 . Why is it rounding it off ? 

```

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [January 13, 2026, 10:56am UTC](https://forum.arduino.cc/t/accuracy-loss-while-converting-from-int-to-float/1425063/2 "2026-01-13T10:56:46Z")

</div>

When you print a float using Serial.print() you can specify how many decimal places are printed. If you don't do that then the function defaults to printing 2 decimal places

Try this

```arduino
Serial.println(voltPerScan, 7); //print 7 decimal places

```

---

<div class="post-metadata">

**Author:** ![Ardubit](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ardubit/32/264049_2.png) [@Ardubit](https://forum.arduino.cc/u/Ardubit)\
**Post date:** [January 13, 2026, 11:05am UTC](https://forum.arduino.cc/t/accuracy-loss-while-converting-from-int-to-float/1425063/3 "2026-01-13T11:05:20Z")

</div>

Great !! Thanks !!

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [January 13, 2026, 11:11am UTC](https://forum.arduino.cc/t/accuracy-loss-while-converting-from-int-to-float/1425063/4 "2026-01-13T11:11:14Z")

</div>

I am glad that it worked

Is there any reason why you don't save the float value in EEPROM to avoid converting the integer ?

As a matter of interest, what data type is eepromVal ?

---

<div class="post-metadata">

**Author:** ![robtillaart](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robtillaart/32/1098811_2.png) [@robtillaart](https://forum.arduino.cc/u/robtillaart)\
**Post date:** [January 13, 2026, 2:02pm UTC](https://forum.arduino.cc/t/accuracy-loss-while-converting-from-int-to-float/1425063/5 "2026-01-13T14:02:53Z")

</div>

Footnote:  
If you have an integer of the type int32\_t or uint32\_t and it is rather large (uses 24-31 bits),  
it cannot be represented by a float exactly as a float has only 23 bits mantissa.

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [January 13, 2026, 2:25pm UTC](https://forum.arduino.cc/t/accuracy-loss-while-converting-from-int-to-float/1425063/6 "2026-01-13T14:25:54Z")

</div>

> [@Ardubit](#):
>
> The value I expect to get is 0,009375.

You have wanted to see six digits after the decimal point.

But, I have got: `0.0093750` (seven digit after decimal point) after executing:  
`Serial.println(voltPerScan, 7);` which is right.

So, if the 2nd argument of this code: `Serial.println(float number, arg2)` indicates the number of digits after the decimla point, then the actual code should be:

`Serial.println(voltPerScan, 6);`

The default is 2 digts.

---

<div class="post-metadata">

**Author:** ![robtillaart](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robtillaart/32/1098811_2.png) [@robtillaart](https://forum.arduino.cc/u/robtillaart)\
**Post date:** [January 13, 2026, 4:58pm UTC](https://forum.arduino.cc/t/accuracy-loss-while-converting-from-int-to-float/1425063/7 "2026-01-13T16:58:13Z")

</div>

> [@Ardubit](#):
>
> 0,009375

have a look at - [GitHub - RobTillaart/printHelpers: Arduino library to help formatting data for printing](https://github.com/RobTillaart/printHelpers) - which is a collection of formatters for numbers.e.g. print any float in scientific or engineering format.

e.g. scientific **Serial.print(sci(0.009375, 3)) ==\> 9.375E-3**

The standard Serial.print() cannot print floats larger than ~4 billion while the range of floats goes up to 10^38. On the lower side the standard print round to 0.00 by default. To print very small numbers you need up to 45 decimals (subnormal floats).

---

<div class="post-metadata">

**Author:** ![Ardubit](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ardubit/32/264049_2.png) [@Ardubit](https://forum.arduino.cc/u/Ardubit)\
**Post date:** [January 16, 2026, 6:58am UTC](https://forum.arduino.cc/t/accuracy-loss-while-converting-from-int-to-float/1425063/8 "2026-01-16T06:58:46Z")

</div>

Good doubt !

I simply wanted to handle only INT types. It is easy to trasnmit these over serial from my LabVIEW application . Nothing else !!

---

<div class="post-metadata">

**Author:** ![Ardubit](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ardubit/32/264049_2.png) [@Ardubit](https://forum.arduino.cc/u/Ardubit)\
**Post date:** [January 16, 2026, 7:01am UTC](https://forum.arduino.cc/t/accuracy-loss-while-converting-from-int-to-float/1425063/9 "2026-01-16T07:01:28Z")

</div>

I just work with Voltage values between 0- 5V and the maximum precision is the value 0.009999

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [January 16, 2026, 7:09am UTC](https://forum.arduino.cc/t/accuracy-loss-while-converting-from-int-to-float/1425063/10 "2026-01-16T07:09:17Z")

</div>

> [@Ardubit](#):
>
> maximum precision

**1.** You want 6-digit precision (number of digits after the decimal point). Using `Serila.print(float, n)` command, you can print as many digits as you wish.

**2.** How many accurate digits you want after the decimal point?

**3.** If using Arduino UNO R3's 10-bit ADC at Full Scale (FS) = 5V, how much accuracy can you achieve?

---

<div class="post-metadata">

**Author:** ![Ardubit](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ardubit/32/264049_2.png) [@Ardubit](https://forum.arduino.cc/u/Ardubit)\
**Post date:** [January 16, 2026, 7:31am UTC](https://forum.arduino.cc/t/accuracy-loss-while-converting-from-int-to-float/1425063/11 "2026-01-16T07:31:36Z")

</div>

I am using a MCP 4725 DAC which is 12 bits.

So for a 5V span I should get a per bit resolution of 1.22mv . Which is 0.00122 V.

Accuracy hence cannot be better than this.

---

<div class="post-metadata">

**Author:** ![robtillaart](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robtillaart/32/1098811_2.png) [@robtillaart](https://forum.arduino.cc/u/robtillaart)\
**Post date:** [January 16, 2026, 7:42am UTC](https://forum.arduino.cc/t/accuracy-loss-while-converting-from-int-to-float/1425063/12 "2026-01-16T07:42:41Z")

</div>

> [@Ardubit](#):
>
> I am using a MCP 4725 DAC which is 12 bits.

check - [GitHub - RobTillaart/MCP4725: Arduino library for 12 bit I2C DAC - MCP4725](https://github.com/RobTillaart/MCP4725)

> [@Ardubit](#):
>
> a per bit resolution of 1.22mv .

It is easy to add an `float getMilliVolts()`to the library if needed. That will give you good readable numbers in the low range without using 6 decimals. Just another scale.

Created an issue so it is on my backlog - [Add getMilliVolts() wrapper function · Issue #36 · RobTillaart/MCP4725 · GitHub](https://github.com/RobTillaart/MCP4725/issues/36)

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [January 16, 2026, 8:24am UTC](https://forum.arduino.cc/t/accuracy-loss-while-converting-from-int-to-float/1425063/13 "2026-01-16T08:24:29Z")

</div>

> [@Ardubit](#):
>
> Accuracy hence cannot be better than this.

You mean 5-digit accuracy after decimal point?

Which Arduino are you using?

---

<div class="post-metadata">

**Author:** ![robtillaart](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robtillaart/32/1098811_2.png) [@robtillaart](https://forum.arduino.cc/u/robtillaart)\
**Post date:** [January 16, 2026, 8:27am UTC](https://forum.arduino.cc/t/accuracy-loss-while-converting-from-int-to-float/1425063/14 "2026-01-16T08:27:56Z")

</div>

@Ardubit  
I have created a develop branch in my MCP4725 library, implementing milliVolts wrappers.  
It might (or not) solve your needs by handling the device with mV instead of Volts.

Expect to merge and release 0.4.3 later today

* * *

update: merged and released

> **[GitHub - RobTillaart/MCP4725: Arduino library for 12 bit I2C DAC - MCP4725](https://github.com/RobTillaart/MCP4725)**
>
> Arduino library for 12 bit I2C DAC - MCP4725

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 15, 2026, 8:28am UTC](https://forum.arduino.cc/t/accuracy-loss-while-converting-from-int-to-float/1425063/15 "2026-07-15T08:28:44Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
