suppose i have number a=5.70787644444 how do i consider just first 2 decimal places in that . that is a=5.70. is it possible?
2 次查看(过去 30 天)
显示 更早的评论
please reply as soon as possible.
采纳的回答
Star Strider
2015-2-7
One solution:
a = 5.70787644444;
roundn = @(x,n) fix(x.*10.^n)./10.^n; % Round ‘x’ To ‘n’ Digits To The Right Of The Decimal
ar = roundn(a,2)
produces:
ar =
5.70
更多回答(1 个)
Guillaume
2015-2-7
a = 5.70787644444;
arounded = round(a, 2)
1 个评论
Image Analyst
2015-2-7
Yes, but he didn't ask for the rounded value. You probably just thought that since that's the name Star chose - not a good descriptive name in my opinion since it uses fix() instead of round() and fix() does not round in the sense that most people think of rounding.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!