sepiariver
4/7/2016 - 4:25 AM

MODX output modifier to format number using php number_format

MODX output modifier to format number using php number_format

<?php
if (empty($input) || !is_numeric($input)) return $input;
$opts = array_filter(array_map('trim', explode(',', $options)));
$args = array();
$args['decimals'] = (isset($opts[0])) ? intval($opts[0]) : 2;
$args['dec_point'] = (isset($opts[1])) ? (string) $opts[1] : '.';
$args['thousands_sep'] = (isset($opts[2])) ? (string) $opts[2] : ',';
return number_format(floatval($input), $args['decimals'], $args['dec_point'], $args['thousands_sep']);