I want to reduce accuracy and precision to 3 digits.
3 次查看(过去 30 天)
显示 更早的评论
for example I want to a=2.18+0.139; with 3 digits answer must be 2.31. is any way to do this?
3 个评论
回答(3 个)
Praveen Iyyappan Valsala
2018-4-25
I don't know any inbulit function which can do that. But, you can try something like below
trun=@(num,Ndigits)floor(a*10^Ndigits)/10^Ndigits;
trun_a=trun(a,2);
0 个评论
Walter Roberson
2018-4-25
No, there is no built-in way.
You can use the symbolic toolbox with digits set to 3, but that will round rather than truncate.
1 个评论
Stephen23
2018-4-26
Note that setting the digits does not mean that calculations will be performed with exactly that precision, because calculations may use guard digits.
Tom Wenk
2018-4-25
Like Walter Roberson stated, I think you have to use the symbolic toolbox for that.
Maybe this function from the toolbox can help you: https://de.mathworks.com/help/symbolic/digits.html
3 个评论
Walter Roberson
2018-5-2
For addition: multiply the original values by 100, take floor() or fix(). Do the addition. Divide the result by 100.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!