# Why is this an InexactError()?

**URL:** https://discourse.julialang.org/t/why-is-this-an-inexacterror/7645
**Category:** New to Julia
**Created:** [December 9, 2017, 6:22am UTC](https://discourse.julialang.org/t/why-is-this-an-inexacterror/7645 "2017-12-09T06:22:53Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![buzaku](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/buzaku/32/3413_2.png) [@buzaku](https://discourse.julialang.org/u/buzaku)
#### Post date: [December 9, 2017, 6:22am UTC](https://discourse.julialang.org/t/why-is-this-an-inexacterror/7645/1 "2017-12-09T06:22:53Z")

</div>

This is an attempt to translate an example from K&R C. I am unable to parse the InexactError() the code throws up.

```julia
struct Point
    x::Int
    y::Int

    function Point()
        new(0, 0)
    end

    function Point(i::Union{Int, Float64}, j::Union{Int, Float64})
        new(i, j)
    end

end

struct Rect
    p1::Point
    p2::Point
end

screen = Rect(Point(), Point(16.0, 9.0))

middle = Point((screen.p1.x + screen.p2.x)/2, (screen.p1.y + screen.p2.y)/2)

```

middle throws up an InexactError():

```julia
InexactError()
convert(::Type{Int64}, ::Float64) at float.jl:679
Point(::Float64, ::Float64) at KRC.jl:52

```

How do I correct this?

---

<div class="post-metadata">

### Author: ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)
#### Post date: [December 9, 2017, 7:02am UTC](https://discourse.julialang.org/t/why-is-this-an-inexacterror/7645/2 "2017-12-09T07:02:52Z")

</div>

Either change `x` and `y` to be `Float64` or explicitly round using `round((screen.p1.x + screen.p2.x)/2)` or `round(Int, (screen.p1.x + screen.p2.x)/2)`.

```julia
julia> Int(1.2)
ERROR: InexactError()
Stacktrace:
 [1] convert(::Type{Int64}, ::Float64) at .\float.jl:679
 [2] Int64(::Float64) at .\sysimg.jl:24

julia> Int(round(1.2))
1 

julia> round(1.2)
1.0

julia> round(Int, 1.2)
1

julia> Int(1.0)
1

```

---

<div class="post-metadata">

### Author: ![buzaku](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/buzaku/32/3413_2.png) [@buzaku](https://discourse.julialang.org/u/buzaku)
#### Post date: [December 9, 2017, 12:07pm UTC](https://discourse.julialang.org/t/why-is-this-an-inexacterror/7645/3 "2017-12-09T12:07:24Z")

</div>

Got it, my struct definition was wrong. 😐
