Find the precision of a value
이전 댓글 표시
Hello,
Is there a function in matlab that returns the precision of a number? for example, if I have a number 5.34 i want it to return 0.01, if I have a number 4 I want it to return 1 etc..
Thanks in advance for your answers,
댓글 수: 2
Adam
2017년 7월 4일
Given that many double-precision numbers cannot be represented to an exact level of accuracy this would be problematic. e.g.
>> a = 5.34
a =
5.34
>> sprintf( '%0.20f', a )
ans =
'5.33999999999999990000'
You would want this to return 0.01 which may be reasonable, but actually the precision (to use your term) of the number is way smaller.
José-Luis
2017년 7월 4일
Your question might make sense if your number is stored as a string, which your using the fprintf tag suggests.
채택된 답변
추가 답변 (2개)
José-Luis
2017년 7월 4일
Just in case your number is stored as a string:
bla = '5.14';
result = strsplit(bla,'.');
result = numel(result{2})
There are better (faster) ways to do this, but coffee calls.
댓글 수: 2
What about:
bla = '534000';
bla = '0.000045';
bla = '2463.00000';
José-Luis
2017년 7월 4일
Then a regex() could work.
James Tursa
2017년 7월 5일
편집: Stephen23
2017년 9월 26일
1 개 추천
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!