numerical values

Ben Abbott bpabbott at mac.com
Wed Mar 19 13:54:09 CDT 2008


On Wednesday, March 19, 2008, at 11:30AM, "Alan Brummer" <alan.brummer at vodacom.co.za> wrote:
>How do I set a numerical amount to display:
>
> *   Three decimal places (i.e.  123.45678 to 123.467)
> *   Four significant figures (i.e. 123.4567 to 123.5)

There is more than one method to accomplish the 1st, ... one is

disp (sprintf ('Three decimal places: %7.3f', 123.45678)

I don't know of a simple method for the second, but something like the code below will work

x = 123.45678;
n = floor (log10 (x));
x = round (x*10^(3-n)) / 10^(3-n);
disp (sprintf ('Four significant figures: %8g', x))

Ben


More information about the Help-octave mailing list