# Scientic rounding functions?

**URL:** <https://discourse.julialang.org/t/scientic-rounding-functions/6766>\
**Category:** Numerics\
**Created:** [October 30, 2017, 6:40am UTC](https://discourse.julialang.org/t/scientic-rounding-functions/6766 "2017-10-30T06:40:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Hearns](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_hearns/32/1685_2.png) [@John\_Hearns](https://discourse.julialang.org/u/John_Hearns)\
**Post date:** [October 30, 2017, 6:40am UTC](https://discourse.julialang.org/t/scientic-rounding-functions/6766/1 "2017-10-30T06:40:30Z")

</div>

Is there an equivalent of Perl Math::Round package in Julia?  
[Math::Round - Perl extension for rounding numbers - metacpan.org](http://search.cpan.org/~grommel/Math-Round-0.07/Round.pm)

I have found this very useful in the past, the package properly rounds off floating point numbers to a given decimal place.  
This very good article [https://medium.com/@Jernfrost/defining-custom-units-in-julia-and-python-513c34a4c971](https://medium.com/@Jernfrost/defining-custom-units-in-julia-and-python-513c34a4c971)  
has one place where:  
julia\> Fahrenheit(3) + Celsius(4) + Kelvin(4)  
Kelvin(265.0388888888889)  
Erik - great article, and I learned from it. Just that for me that figure should be rounded off…

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [October 30, 2017, 6:45am UTC](https://discourse.julialang.org/t/scientic-rounding-functions/6766/2 "2017-10-30T06:45:59Z")

</div>

Maybe you can specify what is missing in `round`?

---

<div class="post-metadata">

**Author:** ![John\_Hearns](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_hearns/32/1685_2.png) [@John\_Hearns](https://discourse.julialang.org/u/John_Hearns)\
**Post date:** [October 30, 2017, 7:18am UTC](https://discourse.julialang.org/t/scientic-rounding-functions/6766/3 "2017-10-30T07:18:14Z")

</div>

Mauro, thankyou. Yes of course I shoudl have looked there.  
IWill see how the rounding is implemented.

---

<div class="post-metadata">

**Author:** ![ArchieCall](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/archiecall/32/206_2.png) [@ArchieCall](https://discourse.julialang.org/u/ArchieCall)\
**Post date:** [October 30, 2017, 12:26pm UTC](https://discourse.julialang.org/t/scientic-rounding-functions/6766/4 "2017-10-30T12:26:43Z")

</div>

round(1.65429842, 3) will yield 1.654

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [October 30, 2017, 1:17pm UTC](https://discourse.julialang.org/t/scientic-rounding-functions/6766/5 "2017-10-30T13:17:00Z")

</div>

I find this useful sometimes to round to a nearest multiple of something:

```julia
roundnearest(num, frac) = round(num * (1/frac)) * frac

```

```nohighlight
julia> using UnicodePlots
julia> lineplot(1:100, roundnearest.(1:100, 25), canvas=AsciiCanvas)
       ┌────────────────────────────────────────┐ 
   100 │ F""""│ 
       │ | │ 
       │ | │ 
       │ _________ J │ 
       │ | │ 
       │ .` │ 
       │ | │ 
       │ r--------f │ 
       │ | │ 
       │ ,` │ 
       │ | │ 
       │ F""""""""" │ 
       │ | │ 
       │ ,` │ 
     0 │.___J │ 
       └────────────────────────────────────────┘ 
       0 100

```

Wouldn’t call it scientific, though (or even ‘scientic’)… 🙂
