We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    If you're sure you'll always want commas and no decimal point, you should be able to do it in one line:

    return number_format($input);


    No decimal point and the comma are the defaults for number_format().
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
      • 19872
      • 1,078 Posts
      Thanks Bob: Yes. Never decimals. Only commas.

      Just to clarify, are you saying I should change this line in the snippet
      $output = number_format($number, $decimals, $dec_point, $thousands_sep);


      to:
      $output = number_format($input);


      • discuss.answer
        • 3749
        • 24,544 Posts
        I'm suggesting that this line can be the *only* line in the snippet.

        $output = number_format($input);


        If it's US currency, you might want add a dollar sign in front of it:

        $output = '$' . number_format($input);


        [update] The forum insists on converting it, but the first part should be '& # 36;' without the spaces.

          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 19872
          • 1,078 Posts
          Amazingly concise! Thank you for the excellent tips and advice. This recent exposure to php and custom snippets certainly opens the floodgates for developing in MODx. Next stop: More PHP tutorials.

            • 19872
            • 1,078 Posts
            Seems like I can't make that the only item in the snippet.

            <?php
            $number = floatval($input);
            $optionsXpld = @explode('&', $options);
            $optionsArray = array();
            foreach ($optionsXpld as $xpld) {
                $params = @explode('=', $xpld);
                array_walk($params, create_function('&$v', '$v = trim($v);'));
                if (isset($params[1])) {
                    $optionsArray[$params[0]] = $params[1];
                } else {
                    $optionsArray[$params[0]] = '';
                }
            }
            $output = '$' . number_format($input);
            return $output;


            Then applied it to my placeholder like so:

            [[+tv.propPrice:numberformat]]


            Inserts the commas and a dollar sign. Excellent.
              • 3749
              • 24,544 Posts
              Erm ... lines 2, 14, and 15 are the only lines that are actually doing anything. You could remove the rest, since you're not using the options array for anything. I don't think line 2 is necessary (I could be wrong).

              My "one-line" suggestion should have been this (since it didn't return anything):

              return '$' . number_format($input);
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 19872
                • 1,078 Posts
                I go back in a take a look a bit later today. Thanks for following up.