フィルターのクリア

How can I cut four numbers after the decimal number without rounding using MATLAB ?

8 ビュー (過去 30 日間)
I have a number like this:
2.32166873546944
I want to take only four numbers after the decimal point and without rounding, that is, I only want:
2.3216
How do I do this in Matlab ?

採用された回答

John D'Errico
John D'Errico 2023 年 12 月 3 日
編集済み: John D'Errico 2023 年 12 月 3 日
You want to truncate after the 4th decimal place? Easy peasy.
You shift where the decimal place lies, then use floor.
format long g
x = 2.32166873546944
x =
2.32166873546944
y = floor(x*10000)/10000
y =
2.3216
  2 件のコメント
Muhammad Salem
Muhammad Salem 2023 年 12 月 4 日
Thank you so much.
Walter Roberson
Walter Roberson 2023 年 12 月 4 日
If you want "four digits after the decimal place" you should probably use fix() instead of floor()
format long g
x = 2.32166873546944
x =
2.32166873546944
xn = -x
xn =
-2.32166873546944
y1 = floor(x*10000)/10000
y1 =
2.3216
y2 = fix(x*100000)/100000
y2 =
2.32166
y3 = floor(xn*10000)/10000
y3 =
-2.3217
y4 = fix(xn*10000)/10000
y4 =
-2.3216

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by