Question

I am looking for a correct format and do math on currency in MySQL where the prices are dynamically calculated and as such, have a precision greater than 2dp.

calculated unit Price = 1.255
displayed price       = 1.26

If a customer orders 100 of the product:

actual total (100 * 1.255)   = 125.50
displayed total (100 * 1.26) = 126.00

So, If a customer looks at their invoice, and does the maths, they will see that they have been under charged by 50p because I will be charging them £125.50 but they will do the math for themselves and think that they should have been charged £126.00.

I think that the easiest way of tackling this problem is to truncate or round the calculated unit price like ROUND(1.255, 2) or TRUNCATE(1.255, 2) meaning that the display and the accounts will match up.

This is not a problem for very small quantities, however it does become significant when the customer orders more units.

The problem is that I don't want to charge the customer £125.00 or £126.00 I want to charge them £125.50 for 100 items.

Any ideas or should I simply display the price to the customer in 3dp, not 2dp, but round the total?

Was it helpful?

Solution

By rounding the unit price, you are destroying information. The only way to solve this is, as you suggest, to display unit prices to the customer in full.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top