calculate approx of decimal number ?..

Discussion in 'C++' started by mark, Jun 14, 2004.

  1. mark

    mark Guest

    How to calculate the approximation of a given decimal number, say for
    two places after decimal.

    like 10.987 should be approximated to 10.99
    10.947 should be approximated to 10.95

    can someone point me to a web site where one can find implementations
    of standard math library functions like say floor, ceil etc.
     
    mark, Jun 14, 2004
    #1
    1. Advertising

  2. "mark" <> wrote...
    > How to calculate the approximation of a given decimal number, say for
    > two places after decimal.
    >
    > like 10.987 should be approximated to 10.99
    > 10.947 should be approximated to 10.95


    It's called "rounding" and you can find different methods of
    achieving that in different books. Or on Google.

    > can someone point me to a web site where one can find implementations
    > of standard math library functions like say floor, ceil etc.


    Someone possibly can. I can't. Oh, wait, www.google.com
    should be of some help.
     
    Victor Bazarov, Jun 14, 2004
    #2
    1. Advertising

  3. Uzytkownik "mark" <> napisal w wiadomosci
    news:...
    > How to calculate the approximation of a given decimal number, say for
    > two places after decimal.
    >
    > like 10.987 should be approximated to 10.99
    > 10.947 should be approximated to 10.95


    It's really simple:

    double RoundTo2PlacesAfterDecimal(double x)
    {
    return floorf(x * 100 + 0.5) / 100;
    }

    Best regards,
    Marcin
     
    Marcin Kalicinski, Jun 14, 2004
    #3
  4. > double RoundTo2PlacesAfterDecimal(double x)
    > {
    > return floorf(x * 100 + 0.5) / 100;
    > }


    Should be "floor" of course, not "floorf".

    Cheers,
    Marcin
     
    Marcin Kalicinski, Jun 14, 2004
    #4
    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. JVarsoke

    Can't locate String::Approx.pm

    JVarsoke, Feb 28, 2004, in forum: Perl
    Replies:
    1
    Views:
    968
    Joe Smith
    Feb 28, 2004
  2. Replies:
    24
    Views:
    676
    jeffc
    Oct 24, 2003
  3. Michael Hertz
    Replies:
    0
    Views:
    341
    Michael Hertz
    Sep 19, 2004
  4. Michael Hertz
    Replies:
    3
    Views:
    461
    Peter Flynn
    Sep 22, 2004
  5. Replies:
    24
    Views:
    659
    jeffc
    Oct 24, 2003
Loading...

Share This Page