James Taylor wrote:
Rather than doing the maths in the order that you have in $x do: $x = 10.7 * 15 * 0.01;
I'm not sure this will always be true. If you separated it out and put brackets in then maybe you could force it. I'm not sure how PHP would interpret and its order of execution on these.
Well: $x = 10.7 * 15; $x *= 0.01; .. would be a good way to ensure the order of the calculation. (I wouldn't personally even trust parenthesis because you never quite know what the intermediate variable types will be.)
The only other suggestion I would have is why do you have the vat as a fraction (15/100) ? - if its a constant (which it is (bearing in mind iDunno's hardcode comment) wouldnt it be better to have it as 0.15 and :. reducing one calculation by the PHP?
The code I posted was simplified from the real code; the VAT rate is stored in a database along with a host of other settings.
No ones said it yet, so I will. Use a different language!!!
Maybe different commerce package (but that's easier said than done). I don't think PHP is the problem here (do other languages[*] have better solutions?)
[*] By which I means languages well suited to web applications, like Perl, Python, Java, etc. I don't know of any Cobol modules for Apache and wouldn't have a clue how to get started building a website with it!