Floating number format in PHP

function formatNumber($n){

        if(strpos($n,'.') !== false){
            $number = number_format($n,2);
        }else{
            $number = number_format($n);
        }

        return $number;
 }

format(1000.10); // this float number 1,000.10 like this
format(1000); // this int number 1,000 like this

Leave a Comment

Your email address will not be published.