Thread: need to convert double to number with 1 digit after the floating point

1. need to convert double to number with 1 digit after the floating point

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

2. only one Digit after the floating point

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

3. Can I get the number I'm looking for?

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?

4. 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;
}