[Lazarus] Converting pence into pounds and then to string
Mark Morgan Lloyd
markMLl.lazarus at telemetry.co.uk
Wed Dec 12 17:07:57 CET 2012
Howard Page-Clark wrote:
>> > > How's the best way of converting an integer number "208" (that is
>> > > pence) into a string value that is in pounds (2.08)
>
> Here's another variant that provides an optional $, £ or €
>
> uses math;
> function PenceToString(pennies: integer; precision: integer=2;
> currency: string=''): string;
> begin
> Result:= Format(Format(currency+'%%.%df',[precision]),
> [pennies/(10**precision)]);
> end;
Possibly being careful about the encoding of that currency symbol. I'd
also point out that everybody's assuming that OP is asking about
post-decimalisation pennies :-)
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
More information about the Lazarus
mailing list