Re: Maths Functions
- Posted by rforno at tutopia.com
Jul 20, 2001
Derek:
A generalization and a slight improvement for your routines:
function RoundDown(object a)
return floor(a)
end function
function RoundUp(object a)
return -floor(-a)
end function
function Round(object a,integer places)
return floor(a*power(10,places)+0.5)*power(10,-places)
end function
Anyway, for routine Round, the results might not be accurate to 'places'
decimals, due to a small fuzz caused by binary versus decimal arithmetic, so
that if many figures are used for accounting purposes and added up, a
difference of a few cents might crop up. The only solution I know for this
problem is to work internally with cents instead of dollars and show the
results scaled.
----- Original Message -----
From: "Derek Parnell" <ddparnell at bigpond.com>
To: "EUforum" <EUforum at topica.com>
Sent: Friday, July 20, 2001 8:10 AM
Subject: Re: Maths Functions
>
>
> 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
> >
>
>
>
>
>
>
|
Not Categorized, Please Help
|
|