Thread: Floating point decimal movement

  1. #1
    Unregistered
    Guest

    Floating point decimal movement

    Hey guys,

    I was wondering how i could round a floating point number. I know how to do it with the print function but i need to do it in a calculation:

    for example I would like the number 0.009999 to say .01

    thanks

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    This should work, I didn't test it though.
    Code:
    double round ( double value, unsigned decimal )
    {
      return ceil ( value * pow ( 10.0, decimal ) + .5 ) / pow ( 10.0, decimal );
    }
    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. checking for floating point number
    By ssharish2005 in forum C Programming
    Replies: 6
    Last Post: 10-18-2005, 08:14 PM
  2. Floating point #'s, why so much talk about it?
    By scuzzo84 in forum C Programming
    Replies: 5
    Last Post: 09-20-2005, 04:29 PM
  3. floating point operators
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 10-22-2003, 07:53 PM
  4. Understanding floating point
    By Eibro in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 05-11-2003, 03:58 PM
  5. Replies: 2
    Last Post: 09-10-2001, 12:00 PM