No products are associated with this question.
Looks like you want to round to the nearest 0.001. You can do this with the following:
x = 30.6789 % Or whatever your data is base = 0.001; % Or whatever you are rounding too. x_rounded = round(x./base).*base;
Hope this helps!
How about this:
a=30.6789; out = (a - floor(a)) * 10000
You do need the base, for example 10000. Why? Because the fraction never ends as I'm sure you know because you've read the FAQ. Want proof? Check this out:
format long; a % Display it. It won't be 30.6789!
>> a = 30.678899999999999
So that's why you have to pick some number of decimal places.
Play games and win prizes!Learn more