Controlling the precision of floating point number in matlab

前端 未结 3 1250
甜味超标
甜味超标 2021-01-27 09:36

I am dividing a number, say

x=2;
y=1/3;
z=x*y;

I expect z to be 0.66666666666667 i.e. 14 numbers after decimal point and the same

3条回答
  •  [愿得一人]
    2021-01-27 10:08

    you can type in matlab :

    digits(10)
    

    it gives you more floating point precision, or also

    digits(20)
    

    for example:

     a=1/3
    ans = 0.3333
    digits(10)
     vpa(a)
     ans= 0.3333333333
    

    search help of matlab by typing doc in command window and then search : digits

提交回复
热议问题