c语言中有没有四舍五入的函数?

如题所述

c99 开始有 round() 函数处理 四舍5入。
函数原型:
double round (double x);
float roundf (float x);
long double roundl (long double x);
C++11 有 double round (T x);
----
低于c99 的可以自己写,例如: 绝对值+0.5,
绝对值函数原型:
double fabs (double x);
float fabs (float x);
long double fabs (long double x);

正数和负数的 四舍5入 有天花板和地板的 处理,由你自己选择(上靠,下靠) 。
天花板和地板函数原型:
double ceil (double x);
float ceil (float x);
long double ceil (long double x);double floor (double x);
float floor (float x);
long double floor (long double x);
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-03-27
double ceil(double x)返回不小于x的最小整数值(然后转换为double型)。
double floor(double x)返回不大于x的最大整数值。
double round(double x)返回x的四舍五入整数值
int abs(int) 返回整数
double fabs(double) 返回绝对值本回答被网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网