Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
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?
  2 commentaires
KSSV
KSSV le 21 Août 2020
24.5000
In the above where is change in decimal point?
Capulus_love
Capulus_love le 21 Août 2020
sorry, i mean the number of zero under the decimal point

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 21 Août 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.

Plus de réponses (0)

Catégories

En savoir plus sur Numeric Types 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!

Translated by