Thread: flops

  1. #1
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    Question flops

    i was wondering how when my program outputs a deciaml i could round up the nuber like 3.78 to 4

    its probably very simlpe but im a n00b

  2. #2
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    #include <math.h>

    double four = ceil(3.78);

  3. #3
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    i think i understand that

    but what does ceil mean is it a var

  4. #4
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    double ceil(double x); As defined in math.h, ceil is a function which returns the smallest integral value not less than x.

  5. #5
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    im must be really thick (im sorry)

    i have an output lets say this

    double number1 = 3.78;

    cout<<number;
    it will output 3.78 right
    can i have that code so it will make number rounded up to 4
    if atall possible
    i really apecialte ure help

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    There are multiple ways to do it. You could write your own rounding function if you so desired. The way to do it with ceiling is as follows...
    Code:
    #include <iostream>
    using namespace std;
    #include <math.h>
    
    int main( void )
    {
         double number1 = 3.78;
         
         // This outputs 3.78
         cout << "Original number is " << number1 << endl;
     
         number1 = ceil( number1 );
    
         // This outputs 4.00 or something like it
         cout << "New rounded number is " << number1 << endl;
    
         return( 0 );
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem aligning floating point numbers
    By esbo in forum C Programming
    Replies: 4
    Last Post: 01-05-2009, 08:09 PM
  2. Determining required flops to run C code
    By mollyann in forum C Programming
    Replies: 5
    Last Post: 03-30-2005, 01:28 PM