码迷,mamicode.com
首页 > 其他好文 > 详细

浮点数四舍五入到小数点后两位

时间:2020-02-16 21:01:50      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:小数   span   clu   return   change   小数点   str   strong   turn   

#include<stdio.h>
#include<math.h>
double change(double n){
    return round(n * 100) / 100;
}
int main(){
    double n;
    while(scanf("%lf",&n)!= EOF){
        printf("%.2f",change(n));
    }
    return 0;
}

即:将浮点数乘 100,求其四舍五入整数,然后除以100,便可得到 相对应的值

浮点数四舍五入到小数点后两位

标签:小数   span   clu   return   change   小数点   str   strong   turn   

原文地址:https://www.cnblogs.com/expedition/p/12318349.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!