[Lazarus] Converting pence into pounds and then to string

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


On 12/12/2012 15:42, Lukasz Sokol wrote:
> 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 [Format] purist, maybe
> Format('%s%%.%df',[currency, precision],[pennies/(10**precision)]);
> 

  Format('%s%%.%df',[currency, precision]),[pennies/(10**precision)]);
                                         ^
of course!

> No ?
> 
> :)
> Lukasz
> 






More information about the Lazarus mailing list