Can anyone help me? 
Author Message
 Can anyone help me?

I am the Pascal beginner. Anyone can help me to solve this problem?

How can I change the data form Real to string? or
How can I print the real type data, because I can print the data like this
'1.5E+00', but I want to print '1.5'



Wed, 18 Jun 1902 08:00:00 GMT  
 Can anyone help me?

Quote:

> I am the Pascal beginner. Anyone can help me to solve this problem?

> How can I change the data form Real to string? or
> How can I print the real type data, because I can print the data like this
> '1.5E+00', but I want to print '1.5'

Writeln(R:5:1);
--
Franz Glaser, Glasau 3, A-4191 Vorderweissenbach Austria +43-7219-7035-0
Muehlviertler Elektronik Glaser.  Industrial control and instrumentation
http://members.eunet.at/meg-glaser/    http://members.xoom.com/f_glaser/
http://www.geocities.com/~franzglaser/            http://start.at/bedarf


Wed, 18 Jun 1902 08:00:00 GMT  
 Can anyone help me?
Hi Jeffrey

There is more than one way to do this, but here is the easier (longer) way
that works just fine.

You need to use two reserved words. They are VAL and STR. Check your help
files to see how they work. If you want to print a real number eg. 1.5E00, but
you want to see 1.5 then you have to code it as follows (assume this is
variable ZZX)

writeln(ZZX:0:1);

If you want to see 1.500 then code it as follows:

writeln(ZZX:0:3);

Catch the drift?

Best
Marius

Quote:

> I am the Pascal beginner. Anyone can help me to solve this problem?

> How can I change the data form Real to string? or
> How can I print the real type data, because I can print the data like this
> '1.5E+00', but I want to print '1.5'



Wed, 18 Jun 1902 08:00:00 GMT  
 Can anyone help me?

Quote:

>You need to use two reserved words. They are VAL and STR.

You need to learn the difference between reserved words and identifiers. :-)

I use the following (RealStr()) to get nice calculator style output. If
you prefer single type then values 6 and 12 seem to be good for res1
and res2. For Extended use 20 and 28.

{$IFOPT N+}
Type float=double;
const res1:byte=12;
      res2:byte=24;
{$ELSE}
Type float=Real;
const res1:byte=10;
      res2:byte=20;
{$ENDIF}

Procedure Remove_trailing_zeroes(Var st:numstr;i:byte);
var j:byte;
begin
  if pos('.',st)=0 then exit;
  j:=i;
  While st[j]='0' do dec(j);  { Find the last nonzero character }
  if st[j]='.' then dec(j);   { if dot., then lets remove that as well }
  delete(st,j+1,i-j);         { Remove the characters }
  j:=1;
  While st[j]=' ' do inc(j);  { Find the first non blank }
  delete(st,1,j-1);           { remove the leading blanks }
end;

Function RealStr(X:float):numstr;

var st:numstr;
    i:integer;

begin
  if (abs(x)>=1e-4) and (abs(x)<1.0E+9) then begin
     str(x:1:res1,st);
     Remove_trailing_zeroes(st,length(st));
  end
  else begin
    str(x:res2,st);
    Remove_trailing_zeroes(st,Pos('E',st)-1);
    if copy(st,length(st)-3,255)='E+00' then dec(byte(st[0]),4)
  end;
  if st[1]<>'-' then st:=' '+st;
  {$ifopt N+}
  i:=pos('E',st);
  if i>0 then begin
     inc(i,2);
     while (i<=length(st)-2) and (st[i]='0') do delete(st,i,1);
  End;
  {$endif}
  if (length(st)>4) and (copy(st,length(st)-3,255)='E+00') then
       dec(byte(st[0]),4);
  realstr:=st;
end;



Wed, 18 Jun 1902 08:00:00 GMT  
 Can anyone help me?
Hi Ing. Franz Glaser,

Thank you for you help

Jeffrey



Quote:

> > I am the Pascal beginner. Anyone can help me to solve this problem?

> > How can I change the data form Real to string? or
> > How can I print the real type data, because I can print the data like
this
> > '1.5E+00', but I want to print '1.5'

> Writeln(R:5:1);
> --
> Franz Glaser, Glasau 3, A-4191 Vorderweissenbach Austria +43-7219-7035-0
> Muehlviertler Elektronik Glaser.  Industrial control and instrumentation
> http://members.eunet.at/meg-glaser/    http://members.xoom.com/f_glaser/
> http://www.geocities.com/~franzglaser/            http://start.at/bedarf



Wed, 18 Jun 1902 08:00:00 GMT  
 Can anyone help me?
Hi Marius,

Thank you for you help

Jeffrey


Quote:
> Hi Jeffrey

> There is more than one way to do this, but here is the easier (longer) way
> that works just fine.

> You need to use two reserved words. They are VAL and STR. Check your help
> files to see how they work. If you want to print a real number eg. 1.5E00,
but
> you want to see 1.5 then you have to code it as follows (assume this is
> variable ZZX)

> writeln(ZZX:0:1);

> If you want to see 1.500 then code it as follows:

> writeln(ZZX:0:3);

> Catch the drift?

> Best
> Marius


> > I am the Pascal beginner. Anyone can help me to solve this problem?

> > How can I change the data form Real to string? or
> > How can I print the real type data, because I can print the data like
this
> > '1.5E+00', but I want to print '1.5'



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. It's not bad canned meat...

2. i need help on pascal anyone can help?

3. Help variable reads too far THANX to anyone who tries to help

4. pascal help, can anyone help me to learn pascal

5. can anyone help

6. Can anyone help me?

7. Can anyone help ?

8. Help! Anyone who knows *.ico format

9. Can anyone help with odbcint.dll error?

10. can anyone help please!!!!!!!!!!!

11. Can anyone help me ?

12. Delphi Database Problem, can anyone help?

 

 
Powered by phpBB® Forum Software