Scientic rounding functions?

Is there an equivalent of Perl Math::Round package in Julia?
Math::Round - Perl extension for rounding numbers - metacpan.org

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
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…

Maybe you can specify what is missing in round?

2 Likes

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

round(1.65429842, 3) will yield 1.654

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

roundnearest(num, frac) = round(num * (1/frac)) * frac
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’)… :slight_smile: