It’s useful to be able to format a monetary amount so that it formats slightly differently if the value is a whole round number, vs. when it has decimals - ie. if it’s just dollars vs, dollars + cents.

We want it to end looking something like: $64 when it’s a whole number, and $24.56 when it’s not.

In php, to do that, we use fmod to get the modulo of the value, with respect to 1. We can just blindly run a conditional on this to see if it’s a whole number, and just the money_format argument as needed.

$dollarCost = $cost / 100;
$format = '$%i';

if(!fmod($dollarCost, 1)) {
    $format = '$%.0n';
}

return money_format($format, $dollarCost);