Re: I Need Help
- Posted by Michael Bolin <michaeltom at GEOCITIES.COM> Jun 22, 1997
- 964 views
> Hi Michael, > > Unfortunately, this is not useful to me. If I implement it with: > > fprint(1, "4.2%f", round(0.745)) > > what do you think I get? Well, it is 0.74! Strange enough, some of the > values x.xx5 round up in the correct way, but not all of them! Is this a > bug in my processor (P75), or in the 'binary floating point' routines? > I am puzzled over this for a long time already, as I want to do some exac= > t > financial calculating in Euphoria. Isn't this possible at all, or should = > I > maybe disable my math coprocessor? This is not a bug in my routine, it is another bug resulting from binary floating point representation. But I have just modified the function to allow a variable amount of precision, and it will work in cases such as yours. ---------------------------------------------------- function round(atom x,atom precision) precision=power(10,precision) return floor(x*precision+.5)/precision end function ---------------------------------------------------- Just call it with an atom value, and a number of decimal places to round to. You can use values less than one: If you use 0, it will round to the nearest integer. If you use -1, it will round to the nearest 10. If -2, the nearest 100, etc. Regards, Michael Bolin