philipbrown / worldpay

A PHP wrapper for WorldPay (http://worldpay.com)
MIT License
22 stars 13 forks source link

Money should be decimal. #7

Closed khaledelmahdi closed 9 years ago

khaledelmahdi commented 10 years ago

Cant add decimal value in money field.

Money.php line 19 need to be changed:

Assertion::integer($value);

philipbrown commented 10 years ago

No your money value should be an integer.

I am going to rewrite this package to get rid of the Value Objects, but for now your best is to turn your decimals into integers.

Don't store money values as decimals. It leads to rounding errors.

khaledelmahdi commented 10 years ago

I am not sure how it should be integer?

If I am selling something cost £10.20 how I can charge the client £10 or £11? From accounting point of view this is wrong.

philipbrown commented 10 years ago

You work with monetary values in the smallest unit. So £10.20 would be stored in your database as 1020 (as in 1020p). You only convert back to 10.20 when you need to display it.

This prevents the rounding error of floats, see http://culttt.com/2014/05/28/handle-money-currency-web-applications/

In either case, I'm going to remove the restriction on this package very soon.

philipbrown commented 9 years ago

This has been resolved in v3.0