1. Rounding function

Thanks to advice received in this forum I have been able to greatly 
simplify the code for this rounding function.


function RoundOut(atom variable,integer DecPlaces,atom DirFlag) 
    --Variable=variable to be rounded
    --intDecPlaces=round to no of dec places to the right of the decimal
    --point if positive; to the left if negative. Integer required
    --DirFlag   0=round towards zero
    --          +ve=round to next highest number
    --          -ve=round to next lowest number
            var=-floor(-var) 
        end if
        if DirFlag=0 then       --round towards zero 
            if var<0 then       --round up if -ve
                 var=-floor(-var)
            else
                var=floor(var)  --round down if +ve
            end if
        end if
    return var/power(10,DecPlaces)  --correct decimal places      
end function



Regards, Chris

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu