Re: rounding problem
- Posted by George Walters <gwalters at sc.rr.com> Oct 24, 2006
- 505 views
Ricardo M. Forno wrote: > them by means of the float() function [truncate: z = floor(x * 10000); round: > floor(x * 10000 + 0.5)]. When printing them, divide them into 10,000, This is exactly what my round functin does, but produces a different result than sprintf. I would like to know how sprintf does it's rounding. Anyone know?
global function round(atom a, integer b) atom f if b < 0 then return a -- invalid argument, do nothing elsif b = 0 then return floor(a+.5) else f = power(10,b) return floor(a * f +.5 / f) end if end function