help-octave
[Top][All Lists]
Advanced

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

Re: numerical values


From: Francesco Potorti`
Subject: Re: numerical values
Date: Wed, 19 Mar 2008 23:24:54 +0100

>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)

Why not simply
 printf ('Three decimal places: %7.3f\n', 123.45678);

>I don't know of a simple method for the second

printf ('Four significant figures: %.4g\n', 123.45678);

But this only works if the number is not too small or large.  See
"Floating-Point Conversions" in the manual.

-- 
Francesco Potortì (ricercatore)        Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa         Email: address@hidden
Web: http://fly.isti.cnr.it/           Key:   fly.isti.cnr.it/public.key


reply via email to

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