How to round a result to two decimal places

2,880 ビュー (過去 30 日間)
Mo'men Mamdouh
Mo'men Mamdouh 2016 年 10 月 24 日
回答済み: luke 2022 年 9 月 29 日
r=10 (4/3)*pi*r^3 Round the result to two decimal places
  1 件のコメント
Sarath J
Sarath J 2017 年 11 月 22 日
method 1: round(r)
method 2: format bank; r

サインインしてコメントする。

採用された回答

dpb
dpb 2016 年 10 月 24 日
v=(4/3)*pi*r^3;
>> format long g
>> v
v =
4188.79020478639
>> round(v*100)/100
ans =
4188.79
>>

その他の回答 (3 件)

Kirby Fears
Kirby Fears 2016 年 10 月 24 日
Mo'men,
Check out the round function.
r_rounded = round(r,2); % rounds to 2 decimal places
Hope this helps.
  5 件のコメント
Eleanor Betton
Eleanor Betton 2020 年 11 月 11 日
You can write to word with the report generator function. I used this for rounding a table to go into this:
M = round(V*100)/100;
C = num2cell(V);
fun = @(x) sprintf('%0.2f', x);
V = cellfun(fun, C, 'UniformOutput',0);
V=array2table(V);

サインインしてコメントする。


Thabang Kekana
Thabang Kekana 2021 年 6 月 18 日
12.22

luke
luke 2022 年 9 月 29 日
myAns = 2 * (-4-[6+3+(7-(1+8))+12]-3)+5
myAns =
-47
Round the result to two decimal places

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by