如何降低小数关闭不使用C四舍五入 [英] How to cut decimal off without rounding in C
本文介绍了如何降低小数关闭不使用C四舍五入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何切断用C位小数四舍五入没有?
How do I cut off decimal places in C without rounding?
例如,如果数字是 4.48
它只是显示 4.4
%。1F
舍入到 4.5
谢谢!
推荐答案
您可以(AB)使用的事实,整数除法截断,并且不圆:
You can (ab)use the fact that integer division truncates and doesn't round:
float original = 4.48;
int tmp = original * 10; // 44.8 truncated to 44
float truncated = tmp / 10.0; // 4.4
这篇关于如何降低小数关闭不使用C四舍五入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文