Showing only 2 decimals

12 ビュー (過去 30 日間)
Jakob Sievers
Jakob Sievers 2013 年 2 月 28 日
Hi guys
Trivial question, I am sure, but I can't figure this one out: I am rounding numbers to show only two decimals by:
sprintf('%.2f',number)
This doesnt work for values on the order of 1e^{-n} where n is large. The result then becomes 0.00. How do I preserve the knowledge of 1e^{-n} while still only showing two decimals?
Cheers!

採用された回答

Daniel Shub
Daniel Shub 2013 年 2 月 28 日
Is this what you want?
sprintf('%.2e',0.123456789e-10)
ans =
1.23e-11
  1 件のコメント
Jakob Sievers
Jakob Sievers 2013 年 2 月 28 日
Exactly! Thanks! I knew the solution would be simple! :)
Cheers

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by