Apr 17, 2001 #1 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.
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.
Apr 17, 2001 #2 Denster Programmer Apr 9, 2001 198 GB use type casting as below :- #include <stdio.h> void main() { double s = 18.336; int f; f = (int)s; printf("%d",f); } This has the effect of chopping off everything after the decimal point. Upvote 0 Downvote
use type casting as below :- #include <stdio.h> void main() { double s = 18.336; int f; f = (int)s; printf("%d",f); } This has the effect of chopping off everything after the decimal point.
Apr 17, 2001 1 #3 rbobbitt Programmer Aug 17, 2000 566 US You don't even need the cast, just: double s=18.336; int f=s; The decimal portion is silently truncated. Russ bobbitts@hotmail.com http://home.earthlink.net/~bobbitts Upvote 0 Downvote
You don't even need the cast, just: double s=18.336; int f=s; The decimal portion is silently truncated. Russ bobbitts@hotmail.com http://home.earthlink.net/~bobbitts