Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Truncate double data type to integer 1

Status
Not open for further replies.

taz75

Programmer
Apr 17, 2001
15
GB
I need to truncate a double data type and then only work with the "Whole" number part.

ie when the number in question is 18.336 I only need 18.
 
use type casting as below :-

#include <stdio.h>


void main()
{
double s = 18.336;
int f;
f = (int)s;
printf(&quot;%d&quot;,f);
}

This has the effect of chopping off everything after the
decimal point.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top