Is there a way to avoid this inaccuracy when converting an string to a double and then to an unsigned int? I have tried using str2num() but get the same result.Thanks!
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Guillermo Camacho
le 28 Sep 2021
Réponse apportée : Walter Roberson
le 28 Sep 2021
uint64(str2double('132697151393876469'))
%ans =
% uint64
% 132697151393876464
% note that the ans is the same for inputs 1326971513938764XX, where XX is in the range (57-71)
0 commentaires
Réponse acceptée
Walter Roberson
le 28 Sep 2021
format long g
A = sscanf('132697151393876469', '%lu')
class(A)
0 commentaires
Plus de réponses (1)
the cyclist
le 28 Sep 2021
The reason for this is that MATLAB uses double-precision arithmetic by default, which will typically give approximately 15 decimal digits of precision.
0 commentaires
Voir également
Catégories
En savoir plus sur Data Type Conversion 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!