Skip to content

Instantly share code, notes, and snippets.

View benjaminprojas's full-sized avatar
🏠
Working from home

Benjamin Rojas benjaminprojas

🏠
Working from home
  • Awesome Motive, Inc.
  • Atlanta, GA
View GitHub Profile
@benjaminprojas
benjaminprojas / divide_money_evenly.php
Last active April 7, 2023 11:20
Function to divide money (numbers with 2 decimal points) as evenly as possible between any given number of recipients
<?php
echo nl2br(print_r(divide_money_evenly((float)(string) 78.23, 3), true));
function divide_money_evenly($number, $divided_by, $numbers=array()) {
$total = 0;
for($i=1; $i<=$divided_by; $i++) {
if(abs($number - $total) != 0) {
$divided = $number / $divided_by;
if($divided < 1) {
$rounded = 0;
}