Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
i have a problem with calculation of prices
Ex: for a unitcost sx vat 14,00 it generate unitcost inc vat 16,66000000000000014
Comments
Comment #1
pietervogelaar CreditAttribution: pietervogelaar commentedPlease give a better explanation...
What are the steps you're performing?
What is the value ex VAT?
What is the VAT value?
Comment #2
SanduCiprian CreditAttribution: SanduCiprian commentedfor 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
Comment #3
pietervogelaar CreditAttribution: pietervogelaar commentedHmm 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?
Comment #4
SanduCiprian CreditAttribution: SanduCiprian commentedwhen 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
Comment #5
pietervogelaar CreditAttribution: pietervogelaar commentedI 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?
Comment #6
SanduCiprian CreditAttribution: SanduCiprian commentedi 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;
Comment #7
pietervogelaar CreditAttribution: pietervogelaar commentedCommenting 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.
Comment #8
SanduCiprian CreditAttribution: SanduCiprian commentedLinux CentOS 6.3 and PHP version 5.3.8
Comment #9
pietervogelaar CreditAttribution: pietervogelaar commentedHmm... 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.
Comment #10
SanduCiprian CreditAttribution: SanduCiprian commentedI found the source of my problem, the PHP configuration "precision" needs to be set to 15, mine was set 19.