# round() and signif() aren't working

**URL:** https://discourse.julialang.org/t/round-and-signif-arent-working/20343
**Category:** General Usage
**Tags:** question, error
**Created:** [February 1, 2019, 4:45am UTC](https://discourse.julialang.org/t/round-and-signif-arent-working/20343 "2019-02-01T04:45:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![kirboone](https://avatars.discourse-cdn.com/v4/letter/k/45deac/32.png) [@kirboone](https://discourse.julialang.org/u/kirboone)
#### Post date: [February 1, 2019, 4:45am UTC](https://discourse.julialang.org/t/round-and-signif-arent-working/20343/1 "2019-02-01T04:45:29Z")

</div>

Hi, I’m new to Julia.

I’m trying to use the round() command so that an == condition works properly (don’t need 60 decimal points). For example: round(pi, 3) returns:  
ERROR: MethodError: no method matching round(::Irrational{:π}, ::Int64)  
round(5.6789, 3) returns:  
ERROR: MethodError: no method matching round(::Float64, ::Int64)

Attempting to use signif() returns:  
ERROR: UndefVarError: signif not defined

How do I fix Julia to follow its documentation for these basic commands?

---

<div class="post-metadata">

### Author: ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)
#### Post date: [February 1, 2019, 4:51am UTC](https://discourse.julialang.org/t/round-and-signif-arent-working/20343/2 "2019-02-01T04:51:34Z")

</div>

You must be looking at the documentation from an older version of Julia: in 0.7 and later [`round` takes a keyword `digits` or `sigdigits` keyword](https://docs.julialang.org/en/v1/base/math/#Base.round-Tuple%7BType,Any%7D):

```julia
julia> round(pi, digits=3)
3.142

julia> round(pi, sigdigits=3)
3.14

```

However this is probably not a good way to check for approximate equality since it can be very brittle (e.g. very close numbers can round in opposite directions). I would suggest you use [`isapprox`](https://docs.julialang.org/en/v1/base/math/#Base.isapprox) (or its infix form `≈`) instead

---

<div class="post-metadata">

### Author: ![kirboone](https://avatars.discourse-cdn.com/v4/letter/k/45deac/32.png) [@kirboone](https://discourse.julialang.org/u/kirboone)
#### Post date: [February 1, 2019, 1:19pm UTC](https://discourse.julialang.org/t/round-and-signif-arent-working/20343/3 "2019-02-01T13:19:35Z")

</div>

Ok, thanks for the update on the syntax. I think isapprox might be a better way to do what I want since I’ve got to use an equation as the input, and round() appears to only work with simple arithmetic.

However, I’m still having trouble making it do what I want it to.  
@constraint(m, [i = 1:nREGION], isapprox((PRODUCE[i]-CONSUME[i])\*10^9 + sum(VolShip[i,j] for j=1:nREGION) - sum(VolShip[j,i] for j=1:nREGION), 0))

spits out this error:

ERROR: LoadError: LoadError: **Unrecognized sense isapprox**  
Stacktrace:  
[1] \_canonicalize\_sense(::Symbol) at C:\Users\kirbo.julia\packages\JuMP\PbnIJ\src\macros.jl:303  
[2] @constraint(::LineNumberNode, ::Module, ::Vararg{Any,N} where N) at C:\Users\kirbo.julia\packages\JuMP\PbnIJ\src\macros.jl:484

Essentially I’ve got a mass balance problem with multiple options. right now I’ve got it reduced to 3 nodes, but I want to expand. It worked with three briefly before I made inputs with decimal spaces - now Julia’s excessive decimal places screwed things up.

Is there a better function for dealing with open ended macros like JuMP?

---

<div class="post-metadata">

### Author: ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)
#### Post date: [February 2, 2019, 4:49am UTC](https://discourse.julialang.org/t/round-and-signif-arent-working/20343/4 "2019-02-02T04:49:31Z")

</div>

I’m guessing JuMP doesn’t support `isapprox`. The easiest option is to make it an inequality:

```julia
@constraint(m, [i = 1:nREGION], -tol <= (PRODUCE[i]-CONSUME[i])*10^9 + sum(VolShip[i,j] for j=1:nREGION) - sum(VolShip[j,i] for j=1:nREGION) <= tol)

```

for some appropriate value `tol`.
