Rounding towards zero or from zero
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nick Austinos
le 26 Sep 2022
Réponse apportée : Image Analyst
le 26 Sep 2022
Hi all; I want to round 3.6 to 3 but funny enough all the 'tozero' and 'fromzero' tiebreakers are returning the same answer i.e 4 which i dont want. How can this issue be fixed?
x=3.6
y=round(x,"TieBreaker","tozero")
z=round(x,"TieBreaker","fromzero")
0 commentaires
Réponse acceptée
Les Beckham
le 26 Sep 2022
Modifié(e) : Les Beckham
le 26 Sep 2022
There is no tie involved in rounding 3.6. If you wish, you can use floor instead:
floor(3.6)
If x was 3.5 instead, that would be a tie:
x = 3.5;
y=round(x,"TieBreaker","tozero")
z=round(x,"TieBreaker","fromzero")
2 commentaires
Plus de réponses (3)
Steven Lord
le 26 Sep 2022
The tiebreaker methods only apply when the quantity to be rounded is halfway between the two numbers to which it could be rounded. So if you had 3.5 that's halfway between 3 and 4 and the tiebreaker would determine to which of those numbers 3.5 gets rounded.
round(3.5, 'TieBreaker', 'tozero')
round(3.5, 'TieBreaker', 'fromzero')
There's no tie to be broken if you're rounding 3.6.
There are other rounding functions that you may want to use instead of round. See their help or documentation pages for more information on each function's specific behavior.
[fix(3.6), floor(3.6), round(3.6), ceil(3.6)]
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!