Counting all numbers after decimal point.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jonathan
le 2 Avr 2014
Réponse apportée : Walter Roberson
le 2 Avr 2014
Hello everyone,
I have the following program:
function [ dec ] = digits( x )
% DETERMINE how many digits you have in x.
% dec digits after the comma (decimal).
%%COUNT the digits after the comma.
x = abs(x); %in case of negative numbers
dec = 0;
n=0;
y = x*10^n;
while (floor(y)~=y)
dec = dec + 1;
n = n + 1;
y = x*10^n;
end
end
end
This works for nearly every number except, for example when I use it on 0.0221. My program then gives me as answer '5' yet I don't understand why. Is there anybody here who can help me?
Thanks in advance!
Jonathan
0 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!