diff --git a/app/Utils/Number.php b/app/Utils/Number.php index 69383dbb8384..af7fb8f8b50e 100644 --- a/app/Utils/Number.php +++ b/app/Utils/Number.php @@ -181,7 +181,10 @@ class Number /* 08-01-2022 allow increased precision for unit price*/ $v = rtrim(sprintf('%f', $value),"0"); - $precision = strlen(substr(strrchr($v, $decimal), 1)); + // $precision = strlen(substr(strrchr($v, $decimal), 1)); + + if($v<1) + $precision = strlen($v) - strrpos($v, '.') - 1; $value = number_format($v, $precision, $decimal, $thousand); $symbol = $currency->symbol; diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php index f284bcae9458..1fa3c549b248 100644 --- a/app/Utils/Traits/MakesInvoiceValues.php +++ b/app/Utils/Traits/MakesInvoiceValues.php @@ -305,8 +305,14 @@ trait MakesInvoiceValues //$data[$key][$table_type.'.quantity'] = Number::formatValue($item->quantity, $this->client->currency()); //change quantity from localized number, to decimal format with no trailing zeroes 06/09/21 - $data[$key][$table_type.'.quantity'] = rtrim($item->quantity, $locale_info['decimal_point']); - $data[$key][$table_type.'.unit_cost'] = Number::formatMoney($item->cost, $this->client); + + //30-01-2022 - improve rounding display for Unit quantity + $data[$key][$table_type.'.quantity'] = $item->quantity >=1 ? rtrim(number_format($item->quantity, $this->client->currency()->precision), $locale_info['decimal_point']) : rtrim(number_format($item->quantity,15), 0); + // $data[$key][$table_type.'.quantity'] = rtrim($item->quantity, $locale_info['decimal_point']); + + //30-01-2022 - improve rounding display for Unit Cost + $data[$key][$table_type.'.unit_cost'] = Number::formatMoneyNoRounding($item->cost, $this->client); + $data[$key][$table_type.'.cost'] = Number::formatMoney($item->cost, $this->client); $data[$key][$table_type.'.line_total'] = Number::formatMoney($item->line_total, $this->client);