필터 지우기
필터 지우기

rounding a number up to a decimal point

조회 수: 2 (최근 30일)
Alberto Acri
Alberto Acri 2023년 9월 13일
댓글: Stephen23 2023년 9월 13일
Hi! I have a number:
N = 5.00001:5.99999; % N greater than 5 and less than 6
I want to round the number N up so that I get 6.
So, giving some examples:
N = 4.3;
N_out = 5;
N = 5.8;
N_out = 6;
N = 7.1;
N_out = 8;
N = 9.5;
N_out = 10;
N = 1.2;
N_out = 2;
I tried 'round' but it rounds either down or up if N is < or > than 5 (in this case).
N = 5.3; % or N = 5.9;
N_out = round(N,0); % results: N_out = 5; or N_out = 6;
  댓글 수: 1
Stephen23
Stephen23 2023년 9월 13일
Although ROUND is the wrong function, scroll to the bottom of its help page and you will find the "See Also" list of functions, which includes CEIL, FIX, and FLOOR. The more you use the documentation, the easier it is to find things :)

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

채택된 답변

Sathvik
Sathvik 2023년 9월 13일
Hi Alberto
The 'ceil' function rounds up.
N=4.3;
N_out = ceil(N)
N_out = 5
Hope this solves your query

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by