Problems of convert decimal number to a string
27 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Now I want to convert a input decimal number (maybe a input number, not known) to a string, I try to use num2str and string function, but there are some problems that I can not solve.
num = [110.00001, 10.00000000000000001,99.01]';
% I want to num become ["110.00001", "10.00000000000000001","99.01"]
num2str([110.00001, 10.00000000000000001,99.01])
By use num2str it will delete some decimal places, I don't know how to do it, holp someone would help me.
0 Kommentare
Antworten (3)
madhan ravi
am 28 Jun. 2020
You cannot do that.
2 Kommentare
Walter Roberson
am 8 Okt. 2021
The answer is correct, but see https://www.mathworks.com/matlabcentral/answers/555997-problems-of-convert-decimal-number-to-a-string#comment_916237 for explanation.
Ajay Kumar
am 28 Jun. 2020
You can define precision property in num2str. For example:
num = [110.00001, 10.00000000000000001,99.01]';
your_ans = num2str(num,10);
6 Kommentare
Walter Roberson
am 28 Jun. 2020
The exact value stored for 10.0000000001 is
10.0000000001000000082740370999090373516082763671875
Values down to 10.000000000000001 can be distinguished from 10.0
10.0000000000000017763568394002504646778106689453125
It is important to remember for this purpose that double() does not use decimal representation: it uses IEEE 754 Double Precision Binary representation, which is a 64 bit representation with 1 sign bit, 11 exponent bits, and 52 explicit fraction bits, plus one "hidden" fraction bit (it is hidden in the exponent in a way.)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!