Rounding a decimal down
조회 수: 17 (최근 30일)
이전 댓글 표시
추가 답변 (2개)
Vilém Frynta
2022년 12월 2일
편집: Vilém Frynta
2022년 12월 2일
Example:
X = 0.143;
Y = sprintf('%.2f',X);
Y = str2double(Y)
댓글 수: 2
Stephen23
2022년 12월 3일
편집: Stephen23
2022년 12월 3일
It is more efficient to keep this in the numeric domain, rather than converting to text and back.
It also does not work, because SPRINTF rounds values to the nearest digit, it does not round down:
X = 0.147;
Y = sprintf('%.2f',X);
Y = str2double(Y) % Nope, definitely not rounded down.
The answers from Matt J and Les Beckham are correct.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!