MATLAB: Round down and Round up

round down and round up

Hi everyone,
I have two numbers and want to round up and round down them.
minval = 0.4410 and maxval=0.8450
I want to round down the first number and it will be 0.4. The 2nd number after being rounded up will be 0.9.
I tried with floor(minval) it returns 0 and ceil(maxval) it returns 1. Those numbers are not the result I want.
Could someone give me some advice?
I'm using MATLAB R2014a.
Thank you so much.

Best Answer

In R2014b, the round function now supports rounding to a specific number of digits:
minval = 0.4410;
maxval = 0.8450;
r1_minval = round(minval, 1);
r1_maxval = round(maxval, 1);
If you don’t have R2014b, this works:
diground = @(x,d) round(x*10^d)/10^d;
r2_minval = diground(minval,1);
r2_maxval = diground(maxval,1);