Login or Sign Up
Logging in...
Remember me
Log in
Or
Sign Up
Forgot password or user name?
Log in with
Search in titles only
Search in C only
Search
Advanced Search
Forums
Product Launch
Updates
Today's Posts
Member List
Calendar
Home
Forum
Topic
C
prinf formatting problem
Collapse
X
Collapse
Posts
Latest Activity
Photos
Page
of
1
Filter
Time
All Time
Today
Last Week
Last Month
Show
All
Discussions only
Photos only
Videos only
Links only
Polls only
Events only
Filtered by:
Clear All
new posts
Previous
template
Next
sanganaksakha
New Member
Join Date:
Mar 2007
Posts:
1
#1
prinf formatting problem
Mar 14 '07, 04:19 PM
printf("%d", 12.0 / 8);
Why does the above print 0 and not 1.
- SSK
horace1
Recognized Expert
Top Contributor
Join Date:
Nov 2006
Posts:
1510
#2
Mar 14 '07, 04:24 PM
Originally posted by
sanganaksakha
printf("%d", 12.0 / 8);
Why does the above print 0 and not 1.
- SSK
the expression 12.0 / 8 yeilds a double result which you attempt to print as a int using the %d conversion specification. If you cast the result to an int it will print correctly, e.g.
Code:
printf("%d", (int) (12.0 / 8));
Comment
Post
Cancel
Previous
template
Next
Working...
Yes
No
OK
OK
Cancel
👍
👎
☕
Comment