Skip to content

Instantly share code, notes, and snippets.

@Burick
Forked from sepiariver/numberformat.snippet.php
Created December 21, 2017 12:32
Show Gist options
  • Save Burick/ba934a812ec0a09e185886b43125bc62 to your computer and use it in GitHub Desktop.
Save Burick/ba934a812ec0a09e185886b43125bc62 to your computer and use it in GitHub Desktop.
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']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment