suppose i have number a=5.70787644444 how do i consider just first 2 decimal places in that . that is a=5.70. is it possible?

2 ビュー (過去 30 日間)
please reply as soon as possible.

採用された回答

Star Strider
Star Strider 2015 年 2 月 7 日
One solution:
a = 5.70787644444;
roundn = @(x,n) fix(x.*10.^n)./10.^n; % Round ‘x’ To ‘n’ Digits To The Right Of The Decimal
ar = roundn(a,2)
produces:
ar =
5.70
  4 件のコメント

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

その他の回答 (1 件)

Guillaume
Guillaume 2015 年 2 月 7 日
Since 2014b, round takes the number of decimals to round to, so it's just:
a = 5.70787644444;
arounded = round(a, 2)
  1 件のコメント
Image Analyst
Image Analyst 2015 年 2 月 7 日
Yes, but he didn't ask for the rounded value. You probably just thought that since that's the name Star chose - not a good descriptive name in my opinion since it uses fix() instead of round() and fix() does not round in the sense that most people think of rounding.

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

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by