How to round a result to two decimal places

조회 수: 1,860 (최근 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
Miquel
Miquel 2020년 1월 13일
Thanks for the mega-fast answer!
In principle I wanted to copy the matrices from the Variables window in MATLAB. I tried to copy them from the command window with the short g format, as you suggest, but then it is like copying a bunch of text and I don't manage that it gets pasted correctly in the table.
What do you mean with the COM stuff in Word?
Thanks
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

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by