[Lazarus] Converting pence into pounds and then to string

Lukasz Sokol el.es.cr at gmail.com
Wed Dec 12 16:42:43 CET 2012


On 12/12/2012 15:21, 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;
> 

Being purist, maybe
Format('%s%%.%df',[currency, precision],[pennies/(10**precision)]);

No ?

:)
Lukasz






More information about the Lazarus mailing list