December 2005
Beginner to intermediate
618 pages
20h 19m
English
lround
Rounds a floating-point number to an integer
#include <math.h> longlround( doublex); longlroundf( floatx); longlroundl( long doublex);
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 );Read now
Unlock full access