How do I restrict a float value to only two places after the decimal point in C?

前端 未结 17 3049
孤城傲影
孤城傲影 2020-11-22 03:22

How can I round a float value (such as 37.777779) to two decimal places (37.78) in C?

17条回答
  •  迷失自我
    2020-11-22 03:41

    Using %.2f in printf. It only print 2 decimal points.

    Example:

    printf("%.2f", 37.777779);
    

    Output:

    37.77
    

提交回复
热议问题