Integrated Application Platform › Forums › General › RoundUp problems › Re: Re: RoundUp problems
May 28, 2013 at 10:48 pm
#986
Keymaster
I think the definition of RoundDown was wrong. I changed it to be like your RoundUp except with Floor instead of Ceiling. I also improved Floor and Ceiling slightly.
Here’s what I now have in stdlib:
Ceiling()
{
i = .Int()
return this > i ? i + 1 : i
}
Floor()
{
i = .Int()
return this < i ? i - 1 : i
}
Round(digits)
{
factor = .Sign() * 10.Pow(digits.Int())
return (this * factor + .5).Int() / factor
}
RoundDown(digits)
{
factor = 10.Pow(digits.Int())
return (this * factor).Floor() / factor
}
RoundUp(digits)
{
factor = 10.Pow(digits.Int())
return (this * factor).Ceiling() / factor
}