I'm getting double as a result of a function.
now I have to convert it to be a number with only one digit after the floating point, how can I do it?
is there a math function that can help me?
thanx
I'm getting double as a result of a function.
now I have to convert it to be a number with only one digit after the floating point, how can I do it?
is there a math function that can help me?
thanx
double d = 1234.567;
printf( "%.1f\n", d );
the printf only shows the number as if it was with one digit after the floating point.
BUT, I need to save it as a new double/float or even override the double I get from the function, this new variable should have only one digit after the floating point - all the other digits must be zero!!!
I'm using it for a rotation function in OpenGL
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
I looked at http://www.eskimo.com/~scs/C-faq/q14.1.html
and it is about the printing method again.
are you trying to tell me that there is no way I can get a number with only one digit after the floating point?
It's pure maths:
Code:#include <stdio.h> #include <math.h> int main() { double a = 5.123456, b; b = floor( a * 10 ) / 10; printf( "%lf\n", b ); return 0; }