floating point round in C++

Discussion in 'C++' started by John Smith, Dec 14, 2003.

  1. John Smith

    John Smith Guest

    Hello, is there a way to implement the floating point version of round?
    usually for int's it's int(num+.5) but how to do it for floats?

    Thanks.
     
    John Smith, Dec 14, 2003
    #1
    1. Advertising

  2. "John Smith" <> wrote in message
    news:brinrm$19g6$...
    > Hello, is there a way to implement the floating point version of round?
    > usually for int's it's int(num+.5) but how to do it for floats?
    >
    > Thanks.
    >
    >


    #include <math.h>

    double d = floor(num+.5);
     
    Thomas Wintschel, Dec 14, 2003
    #2
    1. Advertising

  3. In article <brinrm$19g6$>, John Smith wrote:
    > Hello, is there a way to implement the floating point version of round?
    > usually for int's it's int(num+.5) but how to do it for floats?

    [-]
    Yeah ...

    int(4.49 + 0.5)

    .... sure 8-}

    Just let me know which bank you're working for lest I'm opening
    an account there.

    Cheers,
    Juergen

    PS: C99 knows of round(double) and roundf(float).

    --
    \ Real name : Juergen Heinzl \ no flames /
    \ EMail Private : \ send money instead /
     
    Juergen Heinzl, Dec 14, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Will Rocisky
    Replies:
    7
    Views:
    365
    Mensanator
    Aug 9, 2008
  2. ma740988
    Replies:
    13
    Views:
    1,068
    James Kanze
    Dec 14, 2008
  3. Saraswati lakki
    Replies:
    0
    Views:
    1,371
    Saraswati lakki
    Jan 6, 2012
  4. Dermot Moynihan
    Replies:
    9
    Views:
    351
    Dermot Moynihan
    Jan 6, 2007
  5. Lucky Nl
    Replies:
    2
    Views:
    118
    Benoit Daloze
    May 26, 2010
Loading...

Share This Page