Floating point decimal movement

This is a discussion on Floating point decimal movement within the C Programming forums, part of the General Programming Boards category; Hey guys, I was wondering how i could round a floating point number. I know how to do it with ...

  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,796
    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, 09: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, 05:29 PM
  3. floating point operators
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 10-22-2003, 08:53 PM
  4. Understanding floating point
    By Eibro in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 05-11-2003, 04:58 PM
  5. Replies: 2
    Last Post: 09-10-2001, 01:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21