• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Using PHP to format numbers

#1
Hi everyone,

I am using the Custom Fields by Waindigo and I was just wondering if there is a way to format them value.

I have a classifieds section and have a spot for price and milage. I would like 30000 to become 30,000 etc. I know how to do this in PHP with
Code:
$english_format_number = number_format($number);
but I have no idea where to put it. Is there a <xen:> tag that I could use to achieve this or?

Thanks for the help!!
 
#3
Wow. Simple enough! Thank you so much. Been scratching my head over this for a while now.

Is there a place where I can find all of the {xen:} helpers or whatever they're called??
 

Chris D

XenForo developer
Staff member
#7
This is a very basic example of how you could do it.

PHP:
        $number = 1234567890;
        if (strlen($number) === 10)
        {
            $part1 = substr($number, 0, 3);
            $part2 = substr($number, 3, 3);
            $part3 = substr($number, 6, 4);
            $formattedNumber = "($part1) $part2-$part3";

            Zend_Debug::dump($formattedNumber);
            // returns string(14) "(123) 456-7890"
        }
You would perhaps want to make that much more robust by adding in some additional validation/error checking, but you get the idea.
 
#8
This is a very basic example of how you could do it.

PHP:
        $number = 1234567890;
        if (strlen($number) === 10)
        {
            $part1 = substr($number, 0, 3);
            $part2 = substr($number, 3, 3);
            $part3 = substr($number, 6, 4);
            $formattedNumber = "($part1) $part2-$part3";

            Zend_Debug::dump($formattedNumber);
            // returns string(14) "(123) 456-7890"
        }
You would perhaps want to make that much more robust by adding in some additional validation/error checking, but you get the idea.
So basically I would just add that to library\XenForo\Template\Helper\Core.php and than call it with xen:?