How to eliminate values after comma, in double value?

10 ビュー (過去 30 日間)
Mira le
Mira le 2023 年 1 月 24 日
編集済み: Stephen23 2023 年 1 月 24 日
Hi every one,
I have a problem
I have a set of double values
like
0.2000 0.2862
I want just use 0.2 and 0.2, I don t need zeros after
  2 件のコメント
Stephen23
Stephen23 2023 年 1 月 24 日
編集済み: Stephen23 2023 年 1 月 24 日
"I want just use 0.2 and 0.2, I don t need zeros after "
Floating point number types do not store formatting information (like how many trailing/leading zeros are displayed).
I suspect that you are mixing up how data are displayed, with what data are stored in memory. Changing how many zeros are displayed makes absolutely no difference to the numeric data stored in memory.
Question: what are you planning on doing with these values? Then we can discuss approriate approaches.
Mira le
Mira le 2023 年 1 月 24 日
Example
In my programm , these values are decreased iteratively, so, when it remains 0.2000
the next value will be 0.1999

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

採用された回答

Stephen23
Stephen23 2023 年 1 月 24 日
A wild guess:
V = [0.2,0.2862]
V = 1×2
0.2000 0.2862
W = fix(V*10)/10
W = 1×2
0.2000 0.2000
  2 件のコメント
Mira le
Mira le 2023 年 1 月 24 日
Thank you for your answer
but I need also to remove these zeros
the results that I want is 0.2 and 0.2
Stephen23
Stephen23 2023 年 1 月 24 日
編集済み: Stephen23 2023 年 1 月 24 日
"but I need also to remove these zeros the results that I want is 0.2 and 0.2"
Then you need to first answer my question here:
It is certainly possible to display numeric values with a certain number of fractional zeros, or select the number of fractional zeros when converting to text:
N = 0.2
N = 0.2000
S = sprintf('%.1f',N)
S = '0.2'
But so far you have not made it clear if text is what you require.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by