フィルターのクリア

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

3 ビュー (過去 30 日間)
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 件のコメント
KSSV
KSSV 2020 年 8 月 21 日
24.5000
In the above where is change in decimal point?
Capulus_love
Capulus_love 2020 年 8 月 21 日
sorry, i mean the number of zero under the decimal point

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2020 年 8 月 21 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by