how rounde no. if third digit after floating more than 5

3 ビュー (過去 30 日間)
huda nawaf
huda nawaf 2013 年 4 月 9 日
hi, I want raounded a number, so I read this link about that http://www.mathworks.com/matlabcentral/answers/37262 But in this case , it rounde any no. ,while I want rounde number meet a condition. for example:
0.2371 be 0.2400
or
0.4546 be 0.4600
but this number 0.2330 , must be not equal 0.2400, must be the same i.e I want round number if the third digit after floating point equal or more than 5
Thanks in advance
  2 件のコメント
Walter Roberson
Walter Roberson 2013 年 4 月 9 日
Then why would 0.4546 round to 0.4600 and not to .4500, considering that the third digit is not equal or more than 5 ?
Are you wanting to do this numerically or for display purposes?
huda nawaf
huda nawaf 2013 年 4 月 10 日
thanks, I supposed 0.4546 is equal 0.4550.
currently, I want it just for display.

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

採用された回答

Walter Roberson
Walter Roberson 2013 年 4 月 10 日
sprintf('%.2f00', round(N * 100) / 100)
Though I admit to being puzzled as to why you want the misleading '00' at the end, why you want 0.2400 instead of 0.24
  1 件のコメント
huda nawaf
huda nawaf 2013 年 4 月 11 日
no , I mean 0.24
thanks, sprints works

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

その他の回答 (1 件)

Jan
Jan 2013 年 4 月 10 日
If you want it just for displaying, what about:
sprintf('%.3f\n', [0.2371, 0.4546])
I'd definitly omit the trilaing zero, because it is not only confusing, but wrong.

カテゴリ

Help Center および File ExchangeDimensionality Reduction and Feature Extraction についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by