[dev] Best strategy to store money values

Luis Felipe Marzagao/Andamentos lfbm.andamentos at gmail.com
Wed Aug 17 00:12:07 UTC 2011


Em 16-08-2011 04:54, Jan Schneider escreveu:
>
> Zitat von Luis Felipe Marzagao <lfbm.andamentos at gmail.com>:
>
>> Hello:
>>
>> I´m using Horde_Rdo, which, by the way, is fantastic, in order to
>> develop an app to control clients' credits and debits.
>>
>> My first impulse was to store the money amount of each transaction as
>> decimal(10,2) (the backend I´m testing is mysql, but I´d like to keep
>> things as abstracted as possible, taking advantage of Horde_Rdo).
>>
>> But then I got confused about what type of Horde_Form variable and
>> column type (in migration style terms) should I use.
>>
>> I have never developed any app involving money values and
>> calculations, so I could use some advice concerning the best
>> strategy/practice before I invest time going the wrong direction.
>>
>> Any pointers are appreciated.
>
> The form type should be "number", the column type "float".
>
> Jan.
>
Thanks. I still have to do some manually conversion, because the 
"number" form type only validates and returns the number wih your local 
decimal point (in my case the comma ',', not the point '.'), which is 
not accepted by mysql float type. It seems mysql expects to receive a 
pointed decimal number (like 500.10), otherwise it will loose the digits 
after the decimal point. But this is something manageable.

Let me enjoy the opportunity to ask how do I tell migrations create the 
column type 'float' with the options (12,2), twelve digits, two being 
after the decimal point. I can't find any reference on how to pass the 
correct parameters to $t->column( .... array(????));

Thanks a lot,
Luis Felipe


More information about the dev mailing list