Re: rounding problem

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

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


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

Search



Quick Links

User menu

Not signed in.

Misc Menu