Prev: A simple question
Next: A simple question
From: Ranjita on 1 Jun 2010 12:00 Hi everyone, Does anyone know a function that I can use to roundoff to a defined number of decimals in Matlab 7.7.0., e.g. if I want to round off 7.7654 to 7.77 and 9.543 to 9.54. Ranjita
From: Walter Roberson on 1 Jun 2010 12:10 Ranjita wrote: > Does anyone know a function that I can use to roundoff to a defined > number of decimals in Matlab 7.7.0., e.g. if I want to round off 7.7654 > to 7.77 and 9.543 to 9.54. If you want to _display_ a number with a certain number of decimal places, use an appropriate printf format; e.g., sprintf('%.2f', 9.543) If you want the number to be stored internally as just the number of decimal places you specify, then there is no way to do that in any binary floating point number system, as 1/10 (and 1/100 and 1/1000 and so on) are not exactly representable in binary floating point. Alternatives to binary floating point are the fixed-point toolbox, the symbolic toolbox, the arbitrary precision arithmetic FEX contribution, or multiplying the data by an appropriate power of 10 and keeping it in that multiplied form.
From: Ranjita on 1 Jun 2010 12:28 Thank you for you reply! To be more specific, I was wondering if there are any equivalents to the ''roundoff'' function in version 7.7.0 (R2008b). I have encountered this function earlier, but I am wondering if I need to install any specific toolboxes, or if this version simply does not recognize the function. Best wishes, Ranjita Walter Roberson <roberson(a)hushmail.com> wrote in message <GhaNn.30416$mi.18479(a)newsfe01.iad>... > Ranjita wrote: > > > Does anyone know a function that I can use to roundoff to a defined > > number of decimals in Matlab 7.7.0., e.g. if I want to round off 7.7654 > > to 7.77 and 9.543 to 9.54. > > If you want to _display_ a number with a certain number of decimal > places, use an appropriate printf format; e.g., sprintf('%.2f', 9.543) > > If you want the number to be stored internally as just the number of > decimal places you specify, then there is no way to do that in any > binary floating point number system, as 1/10 (and 1/100 and 1/1000 and > so on) are not exactly representable in binary floating point. > > Alternatives to binary floating point are the fixed-point toolbox, the > symbolic toolbox, the arbitrary precision arithmetic FEX contribution, > or multiplying the data by an appropriate power of 10 and keeping it in > that multiplied form.
From: Walter Roberson on 1 Jun 2010 12:37 Ranjita wrote: > Thank you for you reply! To be more specific, I was wondering if there > are any equivalents to the ''roundoff'' function in version 7.7.0 > (R2008b). I have encountered this function earlier, but I am wondering > if I need to install any specific toolboxes, or if this version simply > does not recognize the function. There is no roundoff() function in any toolbox. There is a File Exchange Contribution named roundoff(), perhaps you were using that: http://www.mathworks.com/matlabcentral/fileexchange/1374-roundoff Note that the function does not actually do what it says: it only produces the closest possible binary floating point number to the desired number. You can see the inexact value if you print to enough decimal places, such as sprintf('%.64g\n', x)
From: Ranjita on 1 Jun 2010 12:54 Cheers! /Ranjita Walter Roberson <roberson(a)hushmail.com> wrote in message <zHaNn.93171$0B5.36686(a)newsfe05.iad>... > Ranjita wrote: > > Thank you for you reply! To be more specific, I was wondering if there > > are any equivalents to the ''roundoff'' function in version 7.7.0 > > (R2008b). I have encountered this function earlier, but I am wondering > > if I need to install any specific toolboxes, or if this version simply > > does not recognize the function. > > There is no roundoff() function in any toolbox. There is a File Exchange > Contribution named roundoff(), perhaps you were using that: > > http://www.mathworks.com/matlabcentral/fileexchange/1374-roundoff > > Note that the function does not actually do what it says: it only > produces the closest possible binary floating point number to the > desired number. You can see the inexact value if you print to enough > decimal places, such as > > sprintf('%.64g\n', x)
|
Pages: 1 Prev: A simple question Next: A simple question |