How to round decimal number to 5 places?
28 次查看(过去 30 天)
显示 更早的评论
I am working on Coordinate system based on GPS and have got latlong points to 7digit place ..when i convert them to radian, they expand upto 9 place. My code requires only use upto 5 digits for the calculations. I tried using "round" commands but it says too many input arguments. Can anyone help me with this please.
0 个评论
回答(2 个)
Star Strider
2015-3-23
编辑:Star Strider
2015-3-23
It is easy to create your own version in an anonymous function:
roundn = @(x,n) round(x.*10.^n)./10.^n;
pi_5 = roundn(pi,5)
produces:
pi_5 =
3.14159
If you know you always want to round the radian angle to 5 decimal places, change the function to:
round5 = @(x) round(x.*10.^5)./10.^5;
0 个评论
Shantanu Jana
2015-3-23
编辑:Shantanu Jana
2015-3-23
you can do like this
>> a=1.12345678
a =
1.123456780000000
>> sprintf('%0.5f', a)
ans =
1.12346
>>
3 个评论
Michael Stumpf
2020-5-1
I just tried using str2double(ans) , but it ends up displaying all the zeros at the end again
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!