calculate approx of decimal number ?..

M

mark

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.
 
V

Victor Bazarov

mark said:
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.
 
M

Marcin Kalicinski

Uzytkownik "mark said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top