MATLAB: Round (returning a number)

round

i have a value: a = 1.50000 and i want to round it to 1.5 as a number
i use: a = num2str(a, '%7.1')
now: a = 1.5 but it is a string
so i use: a = str2num(a)
but now: a = 1.50000
Argghhh

Best Answer

What do you mean round in this case? If a=1.50123 and you want a=1.5, that is rounding. If a=1.50000, and you want a=1.5, that's just visual.
>> a=1.5
a =
1.5000
>> format short g
>> a
a =
1.5
If you want to put it in a uitable for example, the column format of "short g" still has 4 digits of precision, which means 1.5000. So it looks like you have to first make it string format like you did. To put it in a table anywhere else, you can use num2str() or fprintf('%7.1')