RE: Maths Functions

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

Thanks, in the meantime I tried writing my own. This will round up, 
down, towards zero, or away from zero. To accomplish this last use 
"variable" as "DirFlag". Any advice on improving coding will be 
appreciated. 
I couldn't find "!=" documented anywhere but found it appears to work as 
"not equal to". Is this correct?

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
        end if
        if DirFlag>0 then       --round up
            var=floor(var+1)
        end if
        if DirFlag=0 then       --round towards zero 
            sign=1
            if var<0 then    
                var=var*-1      --absolute value
                sign=-1         --sign of var
            end if
            var=floor(var)*sign --round down and restore sign
        end if
    end if
    return var/power(10,DecPlaces)  --correct decimal places      
end function


Derek Parnell wrote:
> Hi Chris,
> 
> try these....
> 
> function RoundDown(atom a)
>     return floor(a)
> end function
> 
> function RoundUp(atom a)
>     if integer(a) then
>         return a
>     else
>         return floor(a + 1)
>     end if
> end function
> 
> function Round(atom a, integer places)
>     return floor(a * power(10, places) + 0.5) * power(10, -places)
> end function
> 
> ----- Original Message ----- 
> From: "Structural D-zine" <structuraldzine at hotmail.com>
> To: "EUforum" <EUforum at topica.com>
> Sent: Friday, July 20, 2001 7:51 PM
> Subject: Maths Functions
> 
> > I have been looking for maths functions equivalent to the Basic
> > Round(x,no of places)
> > RoundUp
> > RoundDown
> > 
> 
> 
> 



Regards, Chris

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

Search



Quick Links

User menu

Not signed in.

Misc Menu