Re: ESL - math.e - rounding

new topic     » goto parent     » topic index » view thread      » older message » newer message

Juergen Luethje wrote:
> 
> Hi all,
> 
> here are some thoughts concerning ESL rounding functions.
> 
> Any function for rounding a number should take a second argument that
> denotes the number of digital places that we want the result to have,
> e.g.
>     round(77.123456, 3) = 77.123
> 
> There is an IEEE standard for rounding. A *different* way of rounding
> is what we call in German "kaufmaennisches Runden".
> Translated word by word to English, this would be "commercial rounding".
> Does this (or a similar) term exist in English?
>      round_half_even(x,n)     -- according to IEEE
>      round_half_up(x,n)       -- "kaufmaennisches Runden"
> 
> 
> Both functions sometimes return different results, when the (n+1)th
> decimal place of x equals 5:
>      round_half_even()        -- rounds to nearest even value
>      round_half_up()          -- always rounds up  ( surprise! smile )
> 
> -- Example
> x = 7.125
> round_half_even(x,2)    -->  7.12
> round_half_up(x,2)      -->  7.13
> 
> x = 7.135
> round_half_even(x,2)    -->  7.14
> round_half_up(x,2)      -->  7.14
> 
> 
> What do you all think?
> 

round_half_up() would be roof() in qb.
There's also a function called floor() in qb, which always rounds down.

I quite often end up coding my own implementations of these.

Regards, Alexander Toresson

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu