Floating Point Truncating
I''m calculating floating point numbers, except I only want the number to be only two decimal places. How do I truncate the remaining decimal places?
Ex.
12.375 -> 12.37
200.91235 -> 200.91
Thanks in advance
char szTemp;
sprintf(szTemp, "%.2f", 12.375);
will make a string with 12.38 in it (i think, might be 12.37)
Magmai Kai Holmlor
- The disgruntled & disillusioned
sprintf(szTemp, "%.2f", 12.375);
will make a string with 12.38 in it (i think, might be 12.37)
Magmai Kai Holmlor
- The disgruntled & disillusioned
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Thanks, but I want to put the number back into the floating point variable, and not into a string. I suppose I could do what you have, and then use a string to float function to do the conversion, but isn''t there a more direct route? I''m just assuming there would be...
March 28, 2001 12:06 AM
Basic method involved to round number to 1/100th
float num = (float)(12.96453);
int num1 = (int)num;
num = num - num1;
num = (float)(int)(num * 100);
num = num1 + (num / 100);
float num = (float)(12.96453);
int num1 = (int)num;
num = num - num1;
num = (float)(int)(num * 100);
num = num1 + (num / 100);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement