MATLAB: How to calculate digits after decimal point

audiodecimaldigits after decimalsteganographytrailing zeros

Hello everyone! I want to calculate the number of digits after decimal point but want to ignore the trailing zeros. example: 1.2344500 digits after decimal should be 5.
Is there any inbuilt function to count these digits after decimal or to remove trailing zeros? Thanks in advance…

Best Answer

See this related thread:
Using the function in the above link, the number of significant digits after the decimal point could be calculated as follows:
max(sigdigits(x)-floor(log10(abs(x)))-1,0) % Don't count sig digits before decimal pt
EDIT:
If you want to add a digit after the last significant digit, then something like this (assumes x is positive):
x = original_number; % E.g., 123.456
a = added_digit; % E.g., 9
y = x + a*10^(floor(log10(x))-sigdigits(x)); % New number
E.g.,
>> x = 123.456
x =
1.234560000000000e+02
>> a = 9
a =
9
>> y = x + a*10^(floor(log10(x))-sigdigits(x))
y =
1.234569000000000e+02
>> x = 1.23456789123
x =
1.234567891230000
>> a = 9
a =
9
>> y = x + a*10^(floor(log10(x))-sigdigits(x))
y =
1.234567891239000
>> x = 12345.12345
x =
1.234512345000000e+04
>> a = 8
a =
8
>> y = x + a*10^(floor(log10(x))-sigdigits(x))
y =
1.234512345800000e+04