0
>> str = '0009.51998'
>> str2num(str)
>> sscanf(str,'%f')
ans = 9.5200
我想这个:
ans = 9.51998
>> str = '0009.51998'
>> str2num(str)
>> sscanf(str,'%f')
ans = 9.5200
我想这个:
ans = 9.51998
您获得的。显示时只是四舍五入到小数点后四位。做format long
看到更多的精度。
>> str = '0009.51998';
>> x = sscanf(str, '%f')
x =
9.5200
>> format long
>> x
x =
9.519980000000000
>>
您还可以使用str2double
作为替代sscanf
。它比str2num
更安全,更灵活。这是因为str2num
使用eval
命令。例如,请尝试以下操作:
str2num(' figure();imshow(''peppers.png'')')
您可能会对结果感到惊讶。
+ 1的辣椒人物。 – 2012-01-13 04:24:14
如果你已经有一个字符串,你为什么起诉num2str? (我意识到这不会改变你的问题/回答它) – 2012-01-12 17:56:25