Counting number of digits after the decimal points
이전 댓글 표시
Dear colleagues/friends
Kindly help, i need you to kindly teach me how do I count the number of digits after the decimal point of any number in MATLAB.
For exmaple i have the number 1.26500
Which matlab command or algorith i can use to count the non zero digits after the decimal point and get (3)
채택된 답변
추가 답변 (3개)
If the input is numeric,
num=1.26500;
s= char( extractAfter( string(num),'.') )
length(s)
If the input is in string form,
num="1.26500"; %input
s= fliplr( char( extractAfter( num,'.') ))
numel(s)- sum(find(s~='0',1))+1
function [N_decimal] = countdecimal(value)
max_round_dec = 15;
for N_decimal = 0:max_round_dec
val = rem(value,10^(-N_decimal));
if val == 0
return
end
end
end
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!