home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
USCX
/
TURBO-06.ZIP
/
PRINTUSG.INC
< prev
next >
Wrap
Text File
|
1985-02-23
|
3KB
|
96 lines
{========================== Print_Using ===============================}
{ This function provides numeric output formatting similar to that found
in BASIC. By specifying a mask of the form ($##,###,###.##) you can
cause commas to be inserted in the number and control the size of the
print field and the number of decimal places displayed. If left and
right parentheses are included in the mask, negative numbers will be
enclosed in parentheses otherwise they will be preceeded by a minus
sign.
The device parameter controls whether the output goes to the console (c)
or the printer (p). The device parameter may be either upper or lower
case.
Written by: Bill Collins.
Modified by: Bill Todd.
NOTE: The following type declaration will be global to the program that
uses this function. Watch out for name conflicts. }
type
print_using_type = string[80];
Function Print_using(mask: print_using_type; number: real): print_using_type;
const
comma: char = ',';
point: char = '.';
minus_sign: char = '-';
dollar_sign: char = '$';
left_paren: char = '(';
right_paren: char = ')';
var
field_width,
integer_length,
i,
j,
places,
point_position: integer;
using_commas,
parens,
dollars,
decimal,
negative: boolean;
out_string,
integer_string: string[80];
begin
negative := number < 0;
number := Abs(number);
places := 0;
field_width := Length(mask);
using_commas := Pos(comma,mask) > 0;
decimal := Pos(point,mask) > 0;
dollars := Pos(dollar_sign,mask) > 0;
parens := Pos(left_paren,mask) > 0;
If decimal then
begin
point_position := Pos(point,mask);
If parens then
places := field_width - 1 - point_position
else
places := field_width - point_position;
end;
Str(number: 0: places, out_string);
If using_commas then
begin
j := 0;
integer_string := Copy(out_string, 1, Length(out_string) - places);
integer_length := Length(integer_string);
If decimal then integer_length := integer_length - 1;
For i := integer_length downto 2 do
begin
j := j + 1;
If j mod 3 = 0 then Insert(comma, out_string, i);
end;
end; { if using_commas }
If dollars then out_string := dollar_sign + out_string;
If negative then
If parens then
out_string := left_paren + out_string + right_paren
else
out_string := minus_sign + out_string;
Print_using := out_string;
end;