Skip to content

Instantly share code, notes, and snippets.

@sepiariver
Created April 7, 2016 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sepiariver/b48a3c23293822112e06009179045502 to your computer and use it in GitHub Desktop.
Save sepiariver/b48a3c23293822112e06009179045502 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