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
Printable View
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
#include <math.h>
double four = ceil(3.78);
but what does ceil mean is it a var
double ceil(double x); As defined in math.h, ceil is a function which returns the smallest integral value not less than x.
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
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 );
}