How to convert int to float in C?

后端 未结 9 780
花落未央
花落未央 2020-12-03 07:38

I am trying to solve:

int total=0, number=0;
float percentage=0.0;

percentage=(number/total)*100;
printf(\"%.2f\", percentage);

If the val

9条回答
  •  孤街浪徒
    2020-12-03 08:05

    Change your code to:

    int total=0, number=0;
    float percentage=0.0f;
    
    percentage=((float)number/total)*100f;
    printf("%.2f", (double)percentage);
    

提交回复
热议问题