Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Convert large number into short form(show 1k instead of 1,000) using php script


Convert large number into short form


If you want to convert your large number figure into smaller like facebook, twitter etc. count and like just use my following simple php script.

function changeFormat($input)
{
    $suffixes = array('', 'k', 'm', 'g', 't');
    $suffixIndex = 0;

    while(abs($input) >= 1000 && $suffixIndex < sizeof($suffixes))
    {
        $suffixIndex++;
        $input /= 1000;
    }

    return (
        $input > 0
            // precision of 3 decimal places
            ? floor($input * 1000) / 1000
            : ceil($input * 1000) / 1000
        )
        . $suffixes[$suffixIndex];
}


Now if you want to check output use this line...

echo changeFormat(1100);


Please support us, Like us on Facebook.

0 comments:

Post a Comment

 

Copyright @ 2017 HKBlog.