Previous Page
Next Page


Rounds a floating-point number to an integer

#include <math.h>
long lround ( double x  );
long lroundf ( float x  );
long lroundl ( long double x  );

The lround( ) functions are like round( ), except that they return an integer of type long. lround( ) rounds a floating-point number to the nearest integer value. A number halfway between two integers is rounded away from 0. If the result is outside the range of long, a range error may occur (depending on the implementation), and the return value is unspecified.


long costnow;         // Total cost in cents.
long realcost;
double rate;          // Annual interest rate.
int period;           // Time to defray cost.

/* ... obtain the interest rate to use for calculation ... */

realcost = lround( (double)costnow * exp( rate * (double)period ));

printf( "Financed over %d years, the real cost will be $%ld.%2ld.\n",
        period, realcost/100, realcost % 100 );

See Also

rint( ), lrint( ), llrint( ), round( ), llround( ), nearbyint( )

Previous Page
Next Page