在小数点后的浮点数中,我只需要两个值 [英] in float after decimal i want only two value
本文介绍了在小数点后的浮点数中,我只需要两个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在小数点后的浮点数中,我只想显示两个值.
in float after decimal point i want to show only two value
推荐答案
使用printf
[
Use proper format specification fields ofprintf
[^]. For instance
float x = 1.237f;
printf("x=%8.2f\n", x);
如您所见(输出为x = 1.24
),该值将四舍五入.
:)
As you may observe (the output is x = 1.24
), the value is rounded.
:)
使用sprintf将浮点数格式化为具有所需格式的字符串.我以为你真的在用C,而不是C#?
use sprintf to format your floating point number into a string that has the format you desire. I assume you''re really using C, and not C# ?
这篇关于在小数点后的浮点数中,我只需要两个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文