Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > calculate approx of decimal number ?..

Reply
Thread Tools

calculate approx of decimal number ?..

 
 
mark
Guest
Posts: n/a
 
      06-13-2004
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.
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      06-14-2004
"mark" <(E-Mail Removed)> 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.


 
Reply With Quote
 
 
 
 
Marcin Kalicinski
Guest
Posts: n/a
 
      06-14-2004
Uzytkownik "mark" <(E-Mail Removed)> napisal w wiadomosci
news:(E-Mail Removed) m...
> 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


 
Reply With Quote
 
Marcin Kalicinski
Guest
Posts: n/a
 
      06-14-2004
> double RoundTo2PlacesAfterDecimal(double x)
> {
> return floorf(x * 100 + 0.5) / 100;
> }


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

Cheers,
Marcin


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
converting exponential format number to decimal format number Fei Liu Perl Misc 21 12-16-2006 01:49 AM
format a float number with specific number of decimal point Oscar Lok Ruby 1 11-19-2006 05:59 PM
Conversion from Hexadecimal number into Decimal number dharmdeep@gmail.com C Programming 14 11-16-2006 07:51 PM
convert decimal number in a hexadecimal number ? muss C Programming 13 03-27-2006 08:14 AM
Convert decimal number in binary number makok VHDL 1 02-23-2004 06:04 PM



Advertisments