|
|||||||||||
|
Technical Support Support Resources
Product Information |
Technical SupportGENERAL: CONVERTING FLOATING-POINT NUMBER TO INTEGERInformation in this article applies to:
QUESTIONI would like to convert a floating-point number to an integer. Is there a standard math library routine to accomplish this? ANSWERNo. The C Programming Language does not require library routines to perform simple type conversions. Types are converted using implicit type casting. For example:
long l;
float f;
l = f; // f is converted to a long value
// the result is stored in l
In the above example, the value of the floating-point variable f is converted to a long value and is assigned to l. If the value of f is outside the range of values for a long type, the maximum positive or negative long value is assigned to l. The value ranges for the following integer and floating point types are shown below; Data Type Bits Bytes Value Range -------------------------------------------------------------- signed int 16 2 -32768 to 32767 unsigned int 16 2 0 to 65535 signed long 32 4 -2147483648 to +2147483647 unsigned long 32 4 0 to 4294967295 float (IEEE-754) 32 4 ±1.175494E-38 to ±3.402823E+38 MORE INFORMATION
SEE ALSOLast Reviewed: Friday, July 15, 2005 | ||||||||||
|
|||||||||||