# Integers switch to Real when importing from Excel

**URL:** <https://community.wolfram.com/t/integers-switch-to-real-when-importing-from-excel/26527>\
**Category:** Questions\
**Tags:** data-science, import-and-export\
**Created:** [February 26, 2026, 5:20pm UTC](https://community.wolfram.com/t/integers-switch-to-real-when-importing-from-excel/26527 "2026-02-26T17:20:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rimarlag](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/rimarlag/32/9430_2.png) [@rimarlag](https://community.wolfram.com/u/rimarlag)\
**Post date:** [February 26, 2026, 5:20pm UTC](https://community.wolfram.com/t/integers-switch-to-real-when-importing-from-excel/26527/1 "2026-02-26T17:20:37Z")

</div>

When I import files in Excel all integers are interpreted as real numbers, so I have to convert them back to integers. One solution is to first convert the file from XLSX to CSV an the import it to Wolfram. Is there an easier/faster way?

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [February 26, 2026, 6:41pm UTC](https://community.wolfram.com/t/integers-switch-to-real-when-importing-from-excel/26527/2 "2026-02-26T18:41:43Z")

</div>

I asked the notebook assistant, and it suggested a replacement rule, such as

```
{{{1.`, 2.`, 3.`}}} /. x_Real /; x == Round[x] :> Round[x]

```

---

<div class="post-metadata">

**Author:** ![rimarlag](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/rimarlag/32/9430_2.png) [@rimarlag](https://community.wolfram.com/u/rimarlag)\
**Post date:** [February 26, 2026, 6:55pm UTC](https://community.wolfram.com/t/integers-switch-to-real-when-importing-from-excel/26527/3 "2026-02-26T18:55:46Z")

</div>

Thank you Gianluca. Good idea to use the notebook assistant. I will start using it.

This is a possible solution, but maybe in future editions of Mathematica it automatically interprets integers as integers whn importing Excel files.

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [February 26, 2026, 8:10pm UTC](https://community.wolfram.com/t/integers-switch-to-real-when-importing-from-excel/26527/4 "2026-02-26T20:10:58Z")

</div>

This `Import` shortcoming may be considered a bug. Mine is just a workaround.

---

<div class="post-metadata">

**Author:** ![jose](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/jose/32/26765_2.png) [@jose](https://community.wolfram.com/u/jose)\
**Post date:** [February 27, 2026, 4:24pm UTC](https://community.wolfram.com/t/integers-switch-to-real-when-importing-from-excel/26527/5 "2026-02-27T16:24:05Z")

</div>

Ricardo, it seems that Excel does not internally distinguish reals from integers. It always stores IEEE 64-bit double-precision floating-point numbers, which is what Import returns. Apparently Excel typesets them differently, I guess depending on whether all decimal digits are 0 or not.

---

<div class="post-metadata">

**Author:** ![rimarlag](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/rimarlag/32/9430_2.png) [@rimarlag](https://community.wolfram.com/u/rimarlag)\
**Post date:** [February 27, 2026, 4:33pm UTC](https://community.wolfram.com/t/integers-switch-to-real-when-importing-from-excel/26527/6 "2026-02-27T16:33:26Z")

</div>

Thank you very much José

---

<div class="post-metadata">

**Author:** ![mroge02](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mroge02/32/28775_2.png) [@mroge02](https://community.wolfram.com/u/mroge02)\
**Post date:** [February 28, 2026, 2:19am UTC](https://community.wolfram.com/t/integers-switch-to-real-when-importing-from-excel/26527/7 "2026-02-28T02:19:47Z")

</div>

Here are some alternative conversions and a note about Excel.

```
(* Gianluca's method: compare with tolerance *)
res1 = {{{1.`, 1.` + 7 $MachineEpsilon, 1.` + 8 $MachineEpsilon}}} /. 
   x_Real /; x == Round[x] :> Round[x];
res1 // InputForm
(* {{{1, 1, 1}}} *)

(* Exact comparison *)
res2 = {{{1.`, 1.` + $MachineEpsilon, 1.` + 8 $MachineEpsilon}}} /. 
   x_Real /; x - Round[x] == 0 :> Round[x];
res2 // InputForm
(* {{{1, 1.0000000000000002, 1.0000000000000018}}} *)

(* Tolerance like Excel's *)
res3 = Block[{Internal`$EqualTolerance = Log10[15.999999999]},
   {{{1.`, 1.` + 7 $MachineEpsilon, 1.` + 8 $MachineEpsilon}}} /. 
    x_Real /; x == Round[x] :> Round[x]
   ];
res3 // InputForm
(* {{{1, 1, 1.0000000000000018}}} *)

```

[Velvel Kahan describes](https://people.eecs.berkeley.edu/~wkahan/Mindless.pdf) Excel as using “cosmetic rounding.” Excel seems to try to eliminate small rounding errors when the results are close to a real number with a finite decimal expansion. (Or perhaps, it’s more accurate to say it assumes small differences from such numbers are due to rounding errors.) The parentheses operator seems to turn off the cosmetic rounding and restore IEEE 754 behavior. For instance machine epsilon \varepsilon=2^{-52}, x=1+k\varepsilon is rounded to 1 for k=1,\dots7 but not for k \ge 8 (line 2 in the Excel image below). And x-1 is zero for k=1,\dots7 (line 3). But the parentheses around the Excel formula restores the difference k\varepsilon (line 4).

 ![Screenshot2026-02-27at7.32.40 PM.jpg](https://global.discourse-cdn.com/wolfram/original/2X/1/1f628cb9c2fc053c5b9354cef9786f4ec71c12f4.jpeg)

Note that the raw numbers in line 2 when imported into Mathematica are

```
1.0000000000000002`, 1.0000000000000016`, 1.0000000000000018`

```

None of them are `1` as shown in the spreadsheet or in some of the results of the codes above. If you want to convert only floats that are exactly integers, then I would use the “exact comparison” code above.

---

<div class="post-metadata">

**Author:** ![rimarlag](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/rimarlag/32/9430_2.png) [@rimarlag](https://community.wolfram.com/u/rimarlag)\
**Post date:** [February 28, 2026, 2:15pm UTC](https://community.wolfram.com/t/integers-switch-to-real-when-importing-from-excel/26527/8 "2026-02-28T14:15:58Z")

</div>

Thank you Michael. Great explanation.
