How can I cast an int to a double (C)?
How can I cast an int, stored in a variable, to a double?
I am trying to do this: Code:
double d; |
First, why do you say it's not working? Is it a compile error? What's the compiler's error message? Is it a runtime error? How do you know it's handling it incorrectly? Are you displaying the value after the operation and it's not what you expect?
Need more clarity on what the problem is. What you've given is not actually doing division. You use a backslash ( \ ) as opposed to a forward slash ( / ) in the statement. A forward slash is used for division. A backslash is used to escape a character. Second, what you have should cast the variable correctly. If not, I would suggest multiplying the return values by 1.0. Such as this: Code:
d = (1.0 * strlen(str)) / (1.0 * cols); Regardless, the typecasting you used originally should work. |
Casting an int w/ (double) will do just fine. So, if i were an int, then (double)i would cast i to a double. No need to worry.
|
*Edit*
Nevermind this post, I got it figured out, thank you all. |
All times are GMT -5. The time now is 01:03 AM. |