How to round a result to two decimal places

1.963 Ansichten (letzte 30 Tage)
Mo'men Mamdouh
Mo'men Mamdouh am 24 Okt. 2016
Beantwortet: luke am 29 Sep. 2022
r=10 (4/3)*pi*r^3 Round the result to two decimal places

Akzeptierte Antwort

dpb
dpb am 24 Okt. 2016
v=(4/3)*pi*r^3;
>> format long g
>> v
v =
4188.79020478639
>> round(v*100)/100
ans =
4188.79
>>

Weitere Antworten (3)

Kirby Fears
Kirby Fears am 24 Okt. 2016
Mo'men,
Check out the round function.
r_rounded = round(r,2); % rounds to 2 decimal places
Hope this helps.
  5 Kommentare
Miquel
Miquel am 13 Jan. 2020
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 am 11 Nov. 2020
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);

Melden Sie sich an, um zu kommentieren.


Thabang Kekana
Thabang Kekana am 18 Jun. 2021
12.22

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

Kategorien

Mehr zu Data Type Identification finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by