How to round a result to two decimal places

2.353 views (last 30 days)
Mo'men Mamdouh
Mo'men Mamdouh on 24 Oct 2016
Answered: Thabang Kekana on 18 Jun 2021
r=10 (4/3)*pi*r^3 Round the result to two decimal places
  1 Comment
Sarath J
Sarath J on 22 Nov 2017
method 1: round(r)
method 2: format bank; r

Sign in to comment.

Accepted Answer

dpb on 24 Oct 2016
>> format long g
>> v
v =
>> round(v*100)/100
ans =

More Answers (2)

Kirby Fears
Kirby Fears on 24 Oct 2016
Check out the round function.
r_rounded = round(r,2); % rounds to 2 decimal places
Hope this helps.
Eleanor Betton
Eleanor Betton on 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);

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!

Translated by