Board index » delphi » Display a number with n significant figure

Display a number with n significant figure

Hello,

How can I write a program that can display a number
in the significant figure specified by user?

Thanks for your help.

Tamcy

 

Re:Display a number with n significant figure


     The built-in functions write() and writeln() can format numeric
arguments written to text files.  The syntax is
"write(realvariable:width:precision, integervariable:width)"
where "width" is the (minimum) number of spaces you want the output to
occupy and "precision" (for real variables) is the number of places you
wish to the right of the
decimal point (note that this is, perhaps, something of a misnomer).
Numeric variables are written with leading spaces if they are too small
to fill the format.

     Thus if pi = 3.14159, the statement "writeln (pi:5:0, pi:5:1,
pi:8:3, pi:8:5, pi:8:6)"
will produce :"    3  3.1   3.141 3.141593.141590".  [Note that the 5:0
format may,
in some implementations, include the decimal point ...].

Bob Schor
Pascal Enthusiast

Quote
Tamcy wrote:
> Hello,

> How can I write a program that can display a number
> in the significant figure specified by user?

> Thanks for your help.

> Tamcy

Re:Display a number with n significant figure


Tamcy heeft geschreven in bericht
<8h2h0n$ji...@imsp212.netvigator.com>...

Quote
>Hello,

>How can I write a program that can display a number
>in the significant figure specified by user?

Is this what you need?

{$N+,$E-}

var x:extended;   {or real or double}
       n,d,z:byte;
readln('number?  ',x);
readln('total places?  ',n);
readln('fractional places? ',d);
readln('number of spaces? ',z);
writeln;
writeln('number =',x:n:d);
writeln('* (',z,' spaces in between) * = *',' ':z,'*');
writeln;

Quote
>Thanks for your help.

>Tamcy

You're welcome.
Huub.

Other Threads