在计算中使用double的问题 [英] Problem using double in calculation

查看:74
本文介绍了在计算中使用double的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过简单的计算

double val = 2011.8-1989;

val的结果是22.777777778,而不是22.8.有什么办法可以解决这个问题????

In a simple calculation

double val = 2011.8 - 1989;

The result of val is 22.777777778 instead of 22.8. Is there any way to round this off????

推荐答案

hi
您可以使用modf函数:
http://www.cplusplus.com/reference/clibrary/cmath/modf/ [ ^ ]

最好的问候
Filipe Marques
hi
you can use the modf function:
http://www.cplusplus.com/reference/clibrary/cmath/modf/[^]

Best regards
Filipe Marques


double val = 11.23;
double decimal = val - (int)val;


#include <math.h>
:
:
double val = 2011.8 - 1989;
double roundVal = ceilf(val * 100) / 100;
</math.h>


这篇关于在计算中使用double的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆