if you don't want to use any packages for this and yet want to do this in a laravel way, i suggest you do the following. the solution has a blend of pure PHP. i have tested this in laravel 5 and it works well.
first create HelperServiceProvider by running:
php artisan make:provider HelperServiceProvider
then open config/app.php and register the service provider:
'providers' => [
/* other providers */
'App\Providers\HelperServiceProvider',
]
now create a folder app\Helpers and in that folder create a file moneyformat.php
<?php
/* moneyformat.php */
function rupee_format($num) {
$explrestunits = "" ;
if(strlen($num)>3){
$lastthree = substr($num, strlen($num)-3, strlen($num));
$restunits = substr($num, 0, strlen($num)-3); // extracts the last three digits
$restunits = (strlen($restunits)%2 == 1)?"0".$restunits:$restunits; // explodes the remaining digits in 2's formats, adds a zero in the beginning to maintain the 2's grouping.
$expunit = str_split($restunits, 2);
for($i=0; $i<sizeof($expunit); $i++){
// creates each of the 2's group and adds a comma to the end
if($i==0)
{
$explrestunits .= (int)$expunit[$i].","; // if is first value , convert into integer
}else{
$explrestunits .= $expunit[$i].",";
}
}
$thecash = $explrestunits.$lastthree;
} else {
$thecash = $num;
}
return $thecash; // writes the final format where $currency is the currency symbol.
}
now you'll be able to display the numbers in your blade files like this :
{{ rupee_format($price) }}
references question1, question2