在Octave中使用num2str的奇怪行为 [英] Odd behaviour Using num2str in Octave

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

问题描述

八度中的num2str函数出现问题.

Having issue with the num2str function in Octave.

string = num2str(8.395,3);
        

字符串返回"8.39" 而

String returns "8.39" whereas,

string = num2str(1.395,3);
        

返回"1.4".

怎么可能? 如何获得一致的小数位数?

How can it be possible? How can I get a consistent number of decimals?

推荐答案

IEEE浮点数舍入为正好是中途时最接近的偶数.因此,第一种情况向下舍入为8,第二种情况向上舍入为2.

IEEE floating point rounds to the nearest even number when exactly half-way. So the first case it rounds down towards 8, and in the second one up towards 2.

我认为它将始终显示3位数字( ref ):

I think this will always show 3 digits (ref):

num2str(x,'%4.2f')

这篇关于在Octave中使用num2str的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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