Board index » delphi » A 'format strings' problem

A 'format strings' problem

Hello:

Delphi 3 Pro 3.02, BDE 5.11, dBase & Paradox tables, Win 98, Win NT
Server, ReportBuilder, InfoPower.

I have a financial app which creates fixed length ASCII file, for
transmission to a bank, from a dBase data file. I have a problem in
formatting the *Amount* field to the banks' requirements, which are:

  1) field length of 10
  2) numeric only
  3) no decimal point, commas, dollar sign etc.
  4) left fill with zero's.

Example:  $1,200.95    should become   0000120095

The code that *almost* does this is:

 Write(Outfl,format('%10.10d',[(cbccARdtTableAmount.asinteger * 100 )
]));

This code results in 0000120100 for the example above. It rounds up
the 95 cents to 1 dollar - a big banking no-no.

The *Amount* field in the dBase table is:  numeric, 12, 2

I don't know how to get around the problem where if the *conversion
type character* is *d*, then the argument, in this case Amount, must
be an integer value. I don't see any other way to use *format strings*
to left-pad with zeros, do you?

Thanks for any ideas on this,

Rob.
--
Robert Thompson
Montreal, QC, Canada
... Delphi is far superior to VB but,
    it has a long learning curve.

 

Re:A 'format strings' problem


you are rounding the amount too early (by "asInteger")

Write(Outfl,format('%10.10d',[(cbccARdtTableAmount.asinteger * 100 )
]));

round it later:

Write(Outfl,format('%10.10d',[round(cbccARdtTableAmount.asfloat * 100 )]));

--
Roman
(please remove 'stopspam' in header when replying)
mail: i...@rksolution.cz
URL: www.rksolution.cz

Robert Thompson <robert.thomps...@sympatico.ca> pse v diskusnm
p?spvku:3A16DB11.D4629...@sympatico.ca...

Quote
> Hello:

> Delphi 3 Pro 3.02, BDE 5.11, dBase & Paradox tables, Win 98, Win NT
> Server, ReportBuilder, InfoPower.

> I have a financial app which creates fixed length ASCII file, for
> transmission to a bank, from a dBase data file. I have a problem in
> formatting the *Amount* field to the banks' requirements, which are:

>   1) field length of 10
>   2) numeric only
>   3) no decimal point, commas, dollar sign etc.
>   4) left fill with zero's.

> Example:  $1,200.95    should become   0000120095

> The code that *almost* does this is:

>  Write(Outfl,format('%10.10d',[(cbccARdtTableAmount.asinteger * 100 )
> ]));

> This code results in 0000120100 for the example above. It rounds up
> the 95 cents to 1 dollar - a big banking no-no.

> The *Amount* field in the dBase table is:  numeric, 12, 2

> I don't know how to get around the problem where if the *conversion
> type character* is *d*, then the argument, in this case Amount, must
> be an integer value. I don't see any other way to use *format strings*
> to left-pad with zeros, do you?

Re:A 'format strings' problem


Thanks, Roman - you solution worked perfectly! :)

Now I can start gluing my hair back in!!!

--
Robert Thompson
Montreal, QC, Canada

Re:A 'format strings' problem


Thanks, Roman - your solution worked perfectly! :)

Now I can start gluing my hair back in!!!
--
Robert Thompson
Montreal, QC, Canada

Re:A 'format strings' problem


Write(Outfl,format('%10.10d',[(cbccARdtTableAmount.asfloat * 100 )]));

Using AsInteger rounds and converts to an integer before multiplying by 100.
--
Bill

Re:A 'format strings' problem


Thanks, Bill.
--
Robert Thompson
Montreal, QC, Canada

Other Threads