begin
if dNum <= 19 then
result := ZeroTo19(dNum)
else
result := TwentyTo99(dNum);
end;
function Num2Dollars( dNum: double ) : String;
var
centsString: String;
cents: double;
workVar: double;
begin
result := '';
if dNum < 0 then
raise Exception.Create( 'Negative numbers not supported' );
if dNum > 999999999.99 then
raise Exception.Create( 'Num2Dollars only supports up to the millions at this point!' );
cents := (dNum - Int( dNum )) * 100.0;
if cents = 0.0 then
centsString := 'and 00/100 Dollars'
else if cents < 10 then
centsString := Format( 'and 0%1.0f/100 Dollars', [cents] )
else
centsString := Format( 'and %2.0f/100 Dollars', [cents] );
dNum := Int( dNum - (cents / 100.0) ); // lose the cents
// deal with million's
if (dNum >= 1000000 ) and ( dNum <= 999999999 ) then
begin
workVar := dNum / 1000000;
workVar := Int( workVar );
if (workVar <= 9) then
result := ZeroTo19(workVar)
else if ( workVar <= 99 ) then
result := LessThan99( workVar )
else if ( workVar <= 999 ) then
result := Hundreds( workVar )
else
result := 'mill fubar';
result := result + ' Million';
dNum := dNum - ( workVar * 1000000 );
end;
// deal with 1000's
if (dNum >= 1000 ) and ( dNum <= 999999.99 ) then
begin
// doing the two below statements in one line of code yields some really
// freaky floating point errors
workVar := dNum/1000;
workVar := Int( workVar );
if (workVar <= 9) then
result := ZeroTo19(workVar)
else if ( workVar <= 99 ) then
result := LessThan99( workVar )
else if ( workVar <= 999 ) then
result := Hundreds( workVar )
else
result := 'thou fubar';
result := result + ' Thousand';
dNum := dNum - ( workVar * 1000 );
end;
// deal with 100's
if (dNum >= 100.00 ) and (dNum <= 999.99) then
begin
result := result + ' ' + Hundreds( dNum );
dNum := FloatMod( dNum, 100 );
end;
// format in anything less than 100
if ( dNum > 0) or ((dNum = 0) and (Length( result ) = 0)) then
begin
result := result + ' ' + LessThan99( dNum );
end;
result := result + ' ' + centsString;
end;
end.