<?php

namespace App\Support;

class NumberFormatter
{
    public static function natural($value, $precision = 2, $thousandsSeparator = ',')
    {
        $formatted = number_format((float) $value, $precision, '.', $thousandsSeparator);

        if (strpos($formatted, '.') === false) {
            return $formatted;
        }

        return rtrim(rtrim($formatted, '0'), '.');
    }
}
