Truncating a number without rounding
101 次查看(过去 30 天)
显示 更早的评论
Is it possible to truncate a number in matlab without rounding it to the first decimal point? for example, 5.17 I want it to be 5.1 and not 5.2 Thanks
0 个评论
采纳的回答
Azzi Abdelmalek
2015-8-18
fix(a*10)/10
1 个评论
Walter Roberson
2015-8-18
For negative values you need to figure out whether you want -5.17 to go to -5.1 or to -5.2 . If you want the truncation to be "at most" the original value, then you would use floor(a*10)/10 . If you want the truncation to be "closer to 0" then you would use fix() like Azzi shows.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!