How to remove zeros from double value?

hi every one
I have a set D that contains values in double?
D=0.2352, 0.5263
I want to display
D= 0.23, 0.52
Thak you

3 件のコメント

Dyuman Joshi
Dyuman Joshi 2022 年 12 月 18 日
I think the only way to do it for numeric value is to change the format.
format shortG
D=[0.2352, 0.5263]
D = 1×2
0.2352 0.5263
d=floor(D*100)/100
d = 1×2
0.23 0.52
Walter Roberson
Walter Roberson 2022 年 12 月 18 日
format bank
perhaps?
Walter Roberson
Walter Roberson 2022 年 12 月 18 日
... No, it turns out that format bank rounds

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

回答 (2 件)

VBBV
VBBV 2022 年 12 月 18 日

1 投票

format shortG
D = [0.2352 0.5263]
D = 1×2
0.2352 0.5263
D = round(D(:),3) - [0.005 0.006].'
D = 2×1
0.23 0.52

1 件のコメント

Dyuman Joshi
Dyuman Joshi 2022 年 12 月 18 日
This won't work with random data, it depends on manually putting the values

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

Walter Roberson
Walter Roberson 2022 年 12 月 18 日

0 投票

D = [0.2352, 0.5263];
d = floor(D*100)/100;
%version 1
fprintf('D = '); fprintf('%.2f, ', d(1:end-1)); fprintf('%.2f\n', d(end)); %must be one line for LiveScript
D = 0.23, 0.52
%version 2
disp("D = " + strjoin(compose("%.2f", d), ', '))
D = 0.23, 0.52

カテゴリ

ヘルプ センター および File ExchangeData Type Identification についてさらに検索

製品

リリース

R2017a

タグ

質問済み:

2022 年 12 月 18 日

回答済み:

2022 年 12 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by