i have a problem with calculation of prices

Ex: for a unitcost sx vat 14,00 it generate unitcost inc vat 16,66000000000000014

Comments

pietervogelaar’s picture

Please give a better explanation...

What are the steps you're performing?
What is the value ex VAT?
What is the VAT value?

SanduCiprian’s picture

for exemple I add a new item with the price without vat 14 , the price including vat I don't fill , vat 19 (%).
it will apear into the invoice table with the Unitcost (inc. VAT) 16.66000000000000014 instead of 16.66

if i add an item with the price including vat 16.66, vat 19 i have the same results

pietervogelaar’s picture

Hmm you would suspect 16.66 indeed. 14 * 1.19 = 16.66.

I think it's caused by the float data type. However when the invoice is displayed it rounds to two decimals, so you'll probably see there 16.66 I think?

SanduCiprian’s picture

when the invoice is displayed it doesnt round to two decimals.

but when i click the item's edit button the fields are filled corectly with 14.00 and 16.66

pietervogelaar’s picture

I tested an invoice item on my machine Ubuntu 12.10 with:

amount: 1
value without VAT: 14
VAT: 19

And it displays 16.66 just fine.

What operating system are you on? And what PHP version?

SanduCiprian’s picture

i think i figured it out, i don't know if it is a proper solution

in function _invoice_round_and_format_money($number, $precision = 2) I commented this line // $decimals = isset($exp[1]) ? strlen($exp[1]) : 0;

pietervogelaar’s picture

Commenting it is not a proper solution, it's there with a reason.

Still I'm curious about the operating system you are on and your PHP version... please tell me.

SanduCiprian’s picture

Linux CentOS 6.3 and PHP version 5.3.8

pietervogelaar’s picture

Status: Active » Closed (works as designed)

Hmm... maybe update PHP to the latest version 5.3.* or 5.4.*.

I tested on PHP 5.4.6 and can reproduce it, so I will close this issue now.

SanduCiprian’s picture

I found the source of my problem, the PHP configuration "precision" needs to be set to 15, mine was set 19.