Matlab equivalent to Java bigdecimal rounding of Half_up?
조회 수: 3 (최근 30일)
이전 댓글 표시
Is there a Matlab function that mimics the Half_up rounding in Java bigdecimal? Specifically, when the decimal portion is exactly .5, round is towards positive infinity. Example: 3.5 rounds to 4 and -3.5 rounds to -3. I didn't see anything like this in the help for round().
댓글 수: 0
채택된 답변
Steven Lord
2024년 5월 31일
In release R2022a we added the argument TieBreaker (which can be used case insensitively) to control how ties are broken in round. Are you using an older release?
x = [3.5, -3.5];
round(x, Tiebreaker = "plusinf")
round(x, Tiebreaker = "tozero")
round(x, Tiebreaker = "fromzero") % default
You can use this with the N input argument too.
round(1.25, 1) % Remember "fromzero" is the default
round(1.25, 1, Tiebreaker = "tozero")
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!