Float calculation ..
Hello. I want this to be a float value.
float cx=(CurrentXpos / 256);
So if [CurrentXpos] (which is of type int) equals 128, i want it to be 0,5 as an answer. How do i do that?
Cast it. CurrentXpos is treated as an integer, but ((float)CurrentXpos) is treated as a float.
Why use casting when you don''t have to?
Use:
float cx = (CurrentXpos/256.0f);
Like chowe6685 suggested, except include the f after the #, otherwise, it defualts to a double.
Billy - BillyB@mrsnj.com
(Hey, I''''m no longer anonymous!)
Use:
float cx = (CurrentXpos/256.0f);
Like chowe6685 suggested, except include the f after the #, otherwise, it defualts to a double.
Billy - BillyB@mrsnj.com
(Hey, I''''m no longer anonymous!)
Ok, and how do i format my floats to strings, so i can debug print them?
wsprintf(strDebug, "Debug: %d", cx);
This does not work
wsprintf(strDebug, "Debug: %d", cx);
This does not work

this is because the %d in print prints a decimal, not a double.
afaik, there is no way to printf or scanf doubles, only floats.
you want printf("%f", f)...
afaik, there is no way to printf or scanf doubles, only floats.
you want printf("%f", f)...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement