Search code examples
czero

How to convert float to without zeros and points


I'm programming in C language and I'm in doubt with the conversion of floating values.

I have this summarized code that works perfectly:

float number = get_float("Number: ");
float convert= number * 100; 
printf("Number: %g\n", convert);

Using printf with %g I can see the number without the zeros and points.

Has I how to get the same result of printf with %g, but concatenating in the float convert variable and get the conversion directly ?

Output:

I have it:

0.70 ----> 70.000000

I need it:

0.70 ----> 70

Thank you


Solution

  • What you need is a int. int does not have a decimal part. Try this

    int convert= number * 100;