Variant f value to two decimal places, to the third decimal rounding operation

#include<stdio.h>
float func(float a) // 四舍五入到小数点后2位 
{
    return (int)(a*100+0.5)/100.0;
}
int main()
{
    float a;
    scanf("%f", &a);
    func(a);
    a = func(a);
    printf("%f\n", a);
    return 0;
} 
Published 102 original articles · won praise 93 · views 4972

Guess you like

Origin blog.csdn.net/huangziguang/article/details/104700858