Advertisement

Float calculation ..

Started by May 08, 2002 10:15 AM
6 comments, last by Xces 22 years, 9 months ago
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?
float cx=(CurrentXpos / 256.0);
Advertisement
Cast it. CurrentXpos is treated as an integer, but ((float)CurrentXpos) is treated as a float.
so you mean this:

float cx=((float)CurrentXpos / 256.0);
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!)
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
Advertisement
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)...
If you wanted a Double, couldn''t you just print a "Long Float"? Anyways, he''s using a float variable anyways...

wsprintf(strDebug,"Debug :%f",cx);

is what you''re looking for.

Billy - BillyB@mrsnj.com
(Hey, I''''m no longer anonymous!)

This topic is closed to new replies.

Advertisement