Re: Rounding

P_at_draigBrady.com
Date: 11/04/03


Date: Tue, 04 Nov 2003 12:13:25 +0000

Zunbeltz Izaola wrote:
> Hi to all!
>
> I want to know if it is possible to round a floating number to
> multiples of another number. An example:
> I've spam = 0.36 and foo = 0.38 and i want something like this:
>
>
>>>>round(spam,0.25)
>
> 0.25
>
>>>>round(foo,0.25)
>
> 0.50
>
> I know that builtin round rounds to a decimal position, but is there a
> module (or it is easy to code) with a function like this?

def roundto(num,round_multiple):
     return round(num/round_multiple)*round_multiple

Pádraig.



Relevant Pages

  • Re: Problem With Round Function
    ... I read where they are improving accuracy of floating point ... "Ronald W. Roberts" wrote: ... >> I'm having a problem understanding the Round function. ... >> Num DecPt Answer ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Very weird resolution issue. Bug ????? Seriously !!
    ... that at the abstract machine does one operation at a time; the standards contain no ... In C, floating point calculations ... Or the computer is implementing "round alternately" ... always round 1/2 ULP "down", then the consistency of the rounding leads to a cumulative ...
    (comp.soft-sys.matlab)
  • Tough problem...
    ... I am hoping somebody here has enough expirience ... in math and floating point round off errors, ...
    (borland.public.delphi.language.basm)
  • Re: Rounding
    ... > Now you gets incorrectly round down. ... Never ever use floatingpoint arithmeting when it is money you ... I already limited the number of lines with floating point math to 1, ...
    (comp.os.os2.programmer.misc)
  • Re: sprintf rouding error
    ... "uncorrectness" with floating point conversion leads to the ... zero"), it doesn't round. ... So there is no error at all in any internal representation of $n+0.5, ... power of 2, e. ...
    (comp.lang.perl.misc)