lround


lround

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.

Example

 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( )



C(c) In a Nutshell
C in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596006977
EAN: 2147483647
Year: 2006
Pages: 473

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net