# Taking the nearest decimals possible

1 visualizzazione (ultimi 30 giorni)
Ganesh Kini il 22 Apr 2020
Commentato: Stephen23 il 23 Apr 2020
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
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Adam Danz il 22 Apr 2020
Modificato: Adam Danz il 22 Apr 2020
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 CommentiMostra 1 commento meno recenteNascondi 1 commento meno recente
Ganesh Kini il 22 Apr 2020
Modificato: Ganesh Kini il 22 Apr 2020
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 il 23 Apr 2020
Either ismembertol or do it yourself by comparing the absolute difference against a tolerance limit:
abs(A-B)<tol

Accedi per commentare.

### Categorie

Scopri di più su Logical in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by