# Bangla Currency (Taka) Formatting

Today i wrote a simple code to convert a number to Bangladeshi currency (taka) format. the php format_number puts a comma (“,”) after every 3 digits which is not same for Bangladeshi currency. here is the simple function to do the job for yo. it can handle integer and decimal numbers.

function taka_format(\$amount = 0)
{
\$tmp = explode(“.”,\$amount); // for float or double values
\$strMoney = “”;
\$divide = 1000;
\$amount = \$tmp;
\$amount = (int)(\$amount/\$divide);
while(\$amount>0)
{
\$divide = 100;
\$amount = (int)(\$amount/\$divide);
}

if(substr(\$strMoney, 0, 1) == “0”)
\$strMoney = substr(\$strMoney,1);

if(isset(\$tmp)) // if float and double add the decimal digits here.
{
return \$strMoney.”.”.\$tmp;
}
return \$strMoney;
}

an alternate way of doing this is via substr

function taka_format(\$amount = 0)
{
\$tmp = explode(“.”,\$amount);  // for float or double values
\$strMoney = “”;
\$amount = \$tmp;
\$strMoney .= substr(\$amount, -3,3 ) ;
\$amount = substr(\$amount, 0,-3 ) ;
while(strlen(\$amount)>0)
{
\$strMoney = substr(\$amount, -2,2 ).”,”.\$strMoney;
\$amount = substr(\$amount, 0,-2 );
}

if(isset(\$tmp))         // if float and double add the decimal digits here.
{
return \$strMoney.”.”.\$tmp;
}
return \$strMoney;
}

Posted in: PHP

## 2 thoughts on “Bangla Currency (Taka) Formatting”

1. Tarek Hasan says: Hi
Do you have some thing that would convert numbers into bangla text.. like into LACS, CRORES..
like the below example:
12,34,45,789.12 = “Taka Twelve Crore thirty four lac forty five thousand seven hundred eighty nine and twelve paisa only”
.
I ve got codes written in VB that converts numbers to text into thousands, millions but i need VB code that i can use in EXCELL or ACCESS.

thanks n regards,
Tarek

2. Nobin says: This is a nice thing. I use bd number format for some of my business application. I get a function from a comment at http://bd.php.net/manual/en/function.number-format.php#40558 He write it for Indian people, though Indian and Bangladesh number format is similar so i use this.

I don’t know what is the rule for bd number format.

If the amount is larger then should we write like this:

11,11,00,50,45,650

OR like this:

1,11,100,50,45,650