Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Php function to format the money in Rs. (Nepali)
function money_format_nep($number, $is_unicode=true)
{
//number_format($number,".");
if(strstr($number,"-"))
{
$number = str_replace("-","",$number);
$negative = "-";
}
$split_number = @explode(".",$number);
$rupee = $split_number[0];
$paise = @$split_number[1];
if(@strlen($rupee)>3)
{
$hundreds = substr($rupee,strlen($rupee)-3);
$thousands_in_reverse = strrev(substr($rupee,0,strlen($rupee)-3));
for($i=0; $i<(strlen($thousands_in_reverse)); $i=$i+2)
{
$thousands .= $thousands_in_reverse[$i].$thousands_in_reverse[$i+1].",";
}
$thousands = strrev(trim($thousands,","));
$formatted_rupee = $thousands.",".$hundreds;
}
else
{
$formatted_rupee = $rupee;
}
if((int)$paise>0)
{
$formatted_paise = ".".substr($paise,0,2);
}
else
{
$formatted_paise = ".".substr("00",0,2);
}
if($is_unicode){
return get_nep($negative.$formatted_rupee.$formatted_paise);
}
else{
return $negative.$formatted_rupee.$formatted_paise;
}
}
function get_nep($eng_str){
$replace = array("१","२","३","४","५","६","७","८","९","०" );
$find = array("1","2","3","4","5","6","7","8","9","0" );
$nep_str = str_replace($find, $replace, $eng_str);
return $nep_str;
}
// calling
// if you need the number format in unicode format then call using
money_format_nep("12121244",true);
// if you dont need unicode characters then just pass false
money_format_nep("12121244",false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment