home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / TPPROC19.ZIP / DOLLARST.INC < prev    next >
Encoding:
Text File  |  1985-09-06  |  896 b   |  31 lines

  1. type dlrstr = string[20]; {dollar string for output representation}
  2.  
  3. function DollarString(x:real;decimalpts:integer):dlrstr;
  4.  
  5. var
  6.    xlen,
  7.    cp
  8.         :integer;
  9.    xd:dlrstr;
  10.  
  11. begin
  12.  if not( (0<=decimalpts) and (decimalpts<=3) ) then decimalpts:=2;
  13.  str(x:20:decimalpts,xd);
  14.  while xd[1] in [' ','-'] do delete(xd,1,1);
  15.  {Debug writeln(' xd at a   ',xd:20);}
  16.  xlen:=length(xd);
  17.  cp:=xlen-(3+decimalpts);
  18.  if decimalpts=0 then cp:=cp+1;  {the decimal point is suppressed so adjust}
  19. while cp>1 do
  20.       begin
  21.       insert(',',xd,cp);
  22.       {DEBUG writeln(' xd at b   ',xd:20,'  xlen',xlen:5,' cp',cp:5);}
  23.       xlen:=xlen-6;
  24.       cp:=cp-3;
  25.       end;
  26.  
  27. if x<0 then xd:= '('+xd+')';
  28. {Debug writeln(  ' xd at c   ',xd:20);}
  29. DollarString:=xd;
  30. end;
  31.