in reply to Math::round not rounding correctly

tye is talking about that:
$ perl -e 'printf "%.10f\n%.30f\n", 3010*1.15, 3010*1.15' 3461.5000000000 3461.499999999999545252649113535881
So it seems a quick and dirty hack would be to sprintf the number and then round the string? :)

Replies are listed 'Best First'.
Re^2: Math::round not rounding correctly (string)
by tye (Sage) on Dec 23, 2014 at 20:39 UTC

    A better "work-around" to what is arguably "correct" behavior would be:

    $l=Math::Round::round("$x"); # Math::Round::round($x) # vs. this

    If what you care about is how the rounding compares to the string output for the number, then what you should be rounding is the string output, of course.

    - tye        

Re^2: Math::round not rounding correctly
by bulrush (Scribe) on Dec 23, 2014 at 20:22 UTC
    Hmm. Well this seemed to work in this case. I'll test it out.
    perl -e 'print int(sprintf("%.10f",(3010*1.15))+0.5)."\n"'