Re: sprintf problem...
| From: | Daniel Brown | Date: | Sun, 23 Mar 2008 17:26:11 +0000 |
| Subject: | Re: sprintf problem... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-272017@lists.php.net to get a copy of this message | ||
On Sat, Mar 22, 2008 at 3:37 PM, Richard <php_list@ghz.fr> wrote:
[snip=code!]
> When I have one item at 10.03, the result is : Total Vat = 1.97 - Total
> without vat = 10.03 Total with vat = 12.00
> but if I have two items at 10.03 the result is : Total vat = 3.93 -
> Total without vat = 20.06 Total with vat = 23.99
> but I need it to be : Total vat = 3.94 - Total without vat = 20.06 Total
> with vat = 24.00
Check your math, Richard. You're using sprintf() with the float
correctly, you're just missing how it's rounding.
(10.03 * 19.6) / 100 = 1.96588 (rounded to 1.97)
((10.03 * 19.6) / 100) * 2 = 3.93176 (rounded to 3.93)
If you want it to come out to an even number with the VAT added,
simply round the amount first, then multiply it.
--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283