How can I limit the number of digits displayed by printf after the decimal point?

前端 未结 1 1327
不思量自难忘°
不思量自难忘° 2020-12-19 05:00

I wrote a small program that reads two integers using scanf and then performs various arithmetic calculations. I\'m using printf to display the res

相关标签:
1条回答
  • 2020-12-19 05:34

    use "%.2f" at the place you want.

    For example, modify the following statement

    printf("\n%20s%20lf", "Fraction", quotientdecimal);
    

    into this one :

    printf("\n%20s%.2f", "Fraction", quotientdecimal);
    

    will only display two fraction numbers of the variable quotlentdecimal.

    0 讨论(0)
提交回复
热议问题