필터 지우기
필터 지우기

how can I round a number?

조회 수: 2 (최근 30일)
sama
sama 2015년 4월 20일
댓글: Star Strider 2015년 4월 20일
I am trying to consider 0.0001 as zero in my code. How can I define that MaTLAB rounds my number based on decimal that I need?
Thanks a lot.

채택된 답변

Star Strider
Star Strider 2015년 4월 20일
I am not certain exactly what you want.
One of these should work:
x1 = 0.0001;
x2 = 0.001;
y1 = round(x1)
y2 = round(x2)
roundn = @(x,n) round(x*10.^n)./(10.^n);
z1 = roundn(x1,3)
z2 = roundn(x2,3)
The built-in MATLAB round function rounds to the nearest integer. In R2015a, you can also have it round to a specific number of decimal places, but if you have an earlier version, my ‘roundn’ anonymous function will do the same thing.
Run my code snippet here to find out which of them does what you want.
  댓글 수: 2
sama
sama 2015년 4월 20일
thanks a lot. I was looking for roundn. I was wondering how to get 0.0001 as zero but not 0.001 Thanks a gain
Star Strider
Star Strider 2015년 4월 20일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by