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
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
2015년 2월 7일
a = 5.70787644444;
arounded = round(a, 2)
댓글 수: 1
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 Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!