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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by