# IntegerPart confusion

**URL:** <https://community.wolfram.com/t/integerpart-confusion/7966>\
**Category:** Questions\
**Tags:** numerical-computation\
**Created:** [February 23, 2016, 11:28pm UTC](https://community.wolfram.com/t/integerpart-confusion/7966 "2016-02-23T23:28:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![armanesmaili](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@armanesmaili](https://community.wolfram.com/u/armanesmaili)\
**Post date:** [February 23, 2016, 11:28pm UTC](https://community.wolfram.com/t/integerpart-confusion/7966/1 "2016-02-23T23:28:05Z")

</div>

Try the followings:

```
IntegerPart[3700*(1.13 - 1)]

3700*(1.13 - 1)

```

For the first one the answer is 480 and for the second one 481.!!! This happens just for some values; if you replace 1.13 with 1.12 the answers match.

---

<div class="post-metadata">

**Author:** ![iliang](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/iliang/32/11263_2.png) [@iliang](https://community.wolfram.com/u/iliang)\
**Post date:** [February 23, 2016, 11:47pm UTC](https://community.wolfram.com/t/integerpart-confusion/7966/2 "2016-02-23T23:47:30Z")

</div>

It’s not a bug, of course, that’s how [**floating point**](https://en.wikipedia.org/wiki/Floating_point) arithmetic works.

Also not specific to Mathematica, for example consider the python result

```
Python 2.6.6 (r266:84292, Jul 22 2015, 16:47:47) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 3700*(1.13-1)
480.9999999999996

```

which makes the integer part 480 and not 481.

The Mathematica result is exactly the same,

```
In[1]:= 3700*(1.13-1) // InputForm                                              

Out[1]//InputForm= 480.9999999999996

```

but is just printed as 481., because by default only 6 significant digits are displayed.

---

<div class="post-metadata">

**Author:** ![armanesmaili](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@armanesmaili](https://community.wolfram.com/u/armanesmaili)\
**Post date:** [February 23, 2016, 11:54pm UTC](https://community.wolfram.com/t/integerpart-confusion/7966/3 "2016-02-23T23:54:26Z")

</div>

Thanks Ilian! Then, how one can predict for which values of x in 3700\*(x-1) the answer is a bit smaller or larger than the exact value?

---

<div class="post-metadata">

**Author:** ![iliang](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/iliang/32/11263_2.png) [@iliang](https://community.wolfram.com/u/iliang)\
**Post date:** [February 23, 2016, 11:59pm UTC](https://community.wolfram.com/t/integerpart-confusion/7966/4 "2016-02-23T23:59:35Z")

</div>

While such a prediction can probably be formulated by looking at the binary representation of x, note with Mathematica you can always use extended precision and arrive at the right result

```
In[1]:= 3700*(1.13`20 - 1)

Out[1]= 481.0000000000000000

In[2]:= IntegerPart[%]

Out[2]= 481

```

---

<div class="post-metadata">

**Author:** ![armanesmaili](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@armanesmaili](https://community.wolfram.com/u/armanesmaili)\
**Post date:** [February 24, 2016, 12:03am UTC](https://community.wolfram.com/t/integerpart-confusion/7966/5 "2016-02-24T00:03:13Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![wolframcommunity](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/wolframcommunity/32/8335_2.png) [@wolframcommunity](https://community.wolfram.com/u/wolframcommunity)\
**Post date:** [February 24, 2016, 12:03am UTC](https://community.wolfram.com/t/integerpart-confusion/7966/6 "2016-02-24T00:03:24Z")

</div>

[@Arman Esmaili](http://community.wolfram.com/web/armanesmaili) please do NOT use word “bug” in titles unless it was confirmed.

---

<div class="post-metadata">

**Author:** ![sghuisman](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/sghuisman/32/27850_2.png) [@sghuisman](https://community.wolfram.com/u/sghuisman)\
**Post date:** [February 24, 2016, 11:56am UTC](https://community.wolfram.com/t/integerpart-confusion/7966/7 "2016-02-24T11:56:22Z")

</div>

In addition you could use exact arithmetic by typing 113/100 (rather than 1.13). This way everything will be done exactly.
