Str2num: exact the same conversion
이전 댓글 표시
Hi all,
Quick question: I have a string like this:
rawStrMod = '0.0000000001, 0.3'
I use str2num to convert it to number,
>> str2num(rawStrMod)
ans =
0.000000000100000 0.300000000000000
It gives me 0.000000000100000, not exactly the same as 0.0000000001. Here I use format long. If I change to format short g, it gives me:
>> format short g
>> str2num(rawStrMod)
ans =
1e-10 0.3
How can I get exactly 0.0000000001?
댓글 수: 2
Rik
2018년 3월 3일
Is it just that you want the values to be shown in a specific format? Because the result in both cases is the exact same value, Matlab just shows them differently in the two cases.
Stephen23
2018년 3월 4일
"How can I get exactly 0.0000000001?"
It is not possible to store 0.0000000001 exactly using binary floating point numbers.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!