Taking the nearest decimals possible

조회 수: 1 (최근 30일)
Ganesh Kini
Ganesh Kini 2020년 4월 22일
댓글: Stephen23 2020년 4월 23일
Hi,
I have a query
i have 2 number
1] 1.6778
2] 2.032
How do i take the number 1.6778 to 1.7 ( nearest value)
and 2.032 to 2.0 ?
Kindly help

채택된 답변

Adam Danz
Adam Danz 2020년 4월 22일
편집: Adam Danz 2020년 4월 22일
Y = round(X,N) where N is the number of digits to the right (when positive) or left (negative).
Alternativly,
y = round(X*10)/10;
  댓글 수: 3
Ganesh Kini
Ganesh Kini 2020년 4월 22일
편집: Ganesh Kini 2020년 4월 22일
So i have two values
A = 1.69 and B = 1.8
A = 2.1 and B = 2.4
How do i show it that they are approximately equal without using round
are there any relational operators that i can use?
Stephen23
Stephen23 2020년 4월 23일
Either ismembertol or do it yourself by comparing the absolute difference against a tolerance limit:
abs(A-B)<tol

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

추가 답변 (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