# What is 0.14\*300?

**URL:** <https://discourse.julialang.org/t/what-is-0-14-300/85397>\
**Category:** General Usage\
**Tags:** float\
**Created:** [August 6, 2022, 1:35pm UTC](https://discourse.julialang.org/t/what-is-0-14-300/85397 "2022-08-06T13:35:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![thompsonmj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thompsonmj/32/25172_2.png) [@thompsonmj](https://discourse.julialang.org/u/thompsonmj)\
**Post date:** [August 6, 2022, 1:35pm UTC](https://discourse.julialang.org/t/what-is-0-14-300/85397/1 "2022-08-06T13:35:24Z")

</div>

```julia
julia> 0.14*300
42.00000000000001

julia> Int32(0.14*300)
ERROR: InexactError: Int32(42.00000000000001)
Stacktrace:
 [1] Int32(x::Float64)
   @ Base .\float.jl:791
 [2] top-level scope
   @ REPL[12]:1

```

Or for that matter, it seems like `0.14` has a bug with floating point math …

```julia
julia> 0.14*50
7.000000000000001

julia> 0.14*100
14.000000000000002

julia> 0.14*40
5.6000000000000005

julia> 0.13*40
5.2

julia> 0.14*2203
308.42

julia> 0.14*10040
1405.6000000000001

julia> 0.14*200
28.000000000000004
```

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [August 6, 2022, 1:50pm UTC](https://discourse.julialang.org/t/what-is-0-14-300/85397/2 "2022-08-06T13:50:05Z")

</div>

This is a known [limitation](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) with float point operations. There might be some degree of imprecision because the computer does not represent numbers exactly. You will find similar results in [Python](https://www.geeksforgeeks.org/floating-point-error-in-python/) for example.

---

<div class="post-metadata">

**Author:** ![thompsonmj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thompsonmj/32/25172_2.png) [@thompsonmj](https://discourse.julialang.org/u/thompsonmj)\
**Post date:** [August 6, 2022, 1:51pm UTC](https://discourse.julialang.org/t/what-is-0-14-300/85397/3 "2022-08-06T13:51:44Z")

</div>

So is it safest to always use `Int32(round( math ))` if an integer is expected?

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [August 6, 2022, 2:02pm UTC](https://discourse.julialang.org/t/what-is-0-14-300/85397/4 "2022-08-06T14:02:52Z")

</div>

I suspect it depends on the amount of precision you need. You could use `Int64` or `BigInt` if you need more precision. But I am not really an expert at mitigating float point rounding errors. I think if you describe your needs, someone with more expertise might be able to provide sound guidance.

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [August 6, 2022, 2:05pm UTC](https://discourse.julialang.org/t/what-is-0-14-300/85397/5 "2022-08-06T14:05:11Z")

</div>

It seems like [rational](https://stackoverflow.com/questions/36411447/workaround-for-julias-floating-point-arithmetic) numbers might help with division, but that exhausts my knowledge.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [August 6, 2022, 2:08pm UTC](https://discourse.julialang.org/t/what-is-0-14-300/85397/6 "2022-08-06T14:08:01Z")

</div>

`round(Int32, math)` is better.

---

<div class="post-metadata">

**Author:** ![thompsonmj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thompsonmj/32/25172_2.png) [@thompsonmj](https://discourse.julialang.org/u/thompsonmj)\
**Post date:** [August 6, 2022, 2:08pm UTC](https://discourse.julialang.org/t/what-is-0-14-300/85397/7 "2022-08-06T14:08:59Z")

</div>

For my error, it was just to go into an argument for an array initialization within a loop, e.g. `zeros(Int32( x[i] * 300 ))` and when `x[i]` was `0.14`, it was not happy.

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [August 6, 2022, 2:14pm UTC](https://discourse.julialang.org/t/what-is-0-14-300/85397/8 "2022-08-06T14:14:10Z")

</div>

Gotcha. That might be OK if you are not testing exact equalities in your code. Perhaps you could `isapprox`, but there might be other or better options for such cases.
