help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: numerical values


From: Ben Abbott
Subject: Re: numerical values
Date: Wed, 19 Mar 2008 11:54:09 -0700

On Wednesday, March 19, 2008, at 11:30AM, "Alan Brummer" <address@hidden> 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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]