Azzera filtri
Azzera filtri

How do I change string to double without changing number of zero under decimal point?

3 visualizzazioni (ultimi 30 giorni)
a = '24.5';aa = "24.5";
b = str2double(aa)
d = double(a)
d = double(aa)
c = cast(aa,'double')
c = cast(a,'double')
i know
class(a)
class(aa)
answer is
ans = 'char'
ans = 'string'
Each answer shows either
24.5000
or
[50 52 46 53]
Question is that how can I change class char to double without changing number of zero under decimal point?
24.5
Is there any function?

Risposta accettata

Walter Roberson
Walter Roberson il 21 Ago 2020
You cannot. class double does not keep track of how many trailing decimal points are present. class double is not stored in decimal at all: it is stored in binary floating point using an international standard representation that cannot exactly represent 1/10 (for the same mathematical reasons that decimal cannot exactly represent 1/3)
When you are seeing 2.5000 you are seeing one of the several different ways that the mathematical number can be represented. If you were to command
format long g
and display the number again you would see another representation. format bank would give you another.

Più risposte (0)

Categorie

Scopri di più su Numeric Types in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by