0

I'm trying to write a format print string that outputs this number (float 0.2005) as a percent with only 2 decimals (20.05%).

1

3 Answers 3

3

Use %% to output the % sign itself, and use .2 to control precision.

float f = 0.2005;
printf("%.2f%%\n", f * 100);
Sign up to request clarification or add additional context in comments.

Comments

2

Spontaneously, I would do this:

float a = 0.2005;
printf("%.2f%%\n", a * 100.0);

Comments

0

Code :

main()
{
    float a = 0.2005;
    float b = a * 100;
    printf("%.2f\n",b);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.