Skip to content

Instantly share code, notes, and snippets.

@VladaHejda
Last active October 9, 2017 13:51
Show Gist options
  • Save VladaHejda/489028b03a3d3bda94738ef2681aee24 to your computer and use it in GitHub Desktop.
Save VladaHejda/489028b03a3d3bda94738ef2681aee24 to your computer and use it in GitHub Desktop.
MoneyPHP poor rounding :-\
<?php
$item1 = 99;
$item2 = 199;
$item3 = 57;
$credits = 355;
$profit = new \Money\Money($total, new \Money\Currency(''));
list($discount1, $discount2, $discount3) = $profit->allocate([
($item1 / $total) * 100, // 27.887323943662
($item2 / $total) * 100, // 56.056338028169
($item3 / $total) * 100, // 16.056338028169
]);
// $discount1 = 100 !
// $discount2 = 199
// $discount3 = 56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment