Significant digits

IN is storing too many significant digits in the database, I don’t like the look and am concerned it will result in random hard to track rounding errors.

For example one of my line item costs is stored as: 34.75999999999999801048033987171947956085205078125

It should be 34.76, I suspect this was introduced as an artifact of the v4 to v5 conversion. Is there an automated way to clean this situation?

Hi,

@david can you please advise?

we only check for type when storing the amounts in the line items (float) however we do apply rounding to the native currency when performing any calculations. Here is a short block that you can run in tinker to ensure all of your amounts in line items are converted to 2 decimal precision.

Invoice::withTrashed()->cursor()->each(function ($invoice){

$line_items = $invoice->line_items;

foreach($line_items as $item)
{
$item->cost = round($item->cost,2);
}

$invoice->line_items = $line_items;
$invoice->save();

});
1 Like

Thank you. What is tinker?

From the command line you can run,

PHP artisan tinker

This will allow you to run the above command.

1 Like

Will this round recurring invoices?

For Recurring Invoices, you would just need to change the command from

Invoice::

to

RecurringInvoice::
1 Like