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!

조회 수: 3 (최근 30일)
uint64(str2double('132697151393876469'))
%ans =
% uint64
% 132697151393876464
% note that the ans is the same for inputs 1326971513938764XX, where XX is in the range (57-71)

채택된 답변

Walter Roberson
Walter Roberson 2021년 9월 28일
format long g
A = sscanf('132697151393876469', '%lu')
A = uint64
132697151393876469
class(A)
ans = 'uint64'

추가 답변 (1개)

the cyclist
the cyclist 2021년 9월 28일
The reason for this is that MATLAB uses double-precision arithmetic by default, which will typically give approximately 15 decimal digits of precision.
One possibility, if you have the Symbolic Math Toolbox, is to use variable-precision arithmetic.

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by