 How to convert amount in crores to decimal value in php?

# How to convert amount in crores to decimal value in php?

0 3192

Answer: To convert amount in crores to decimal value in php, here's the code:

`<?php// Create a function for converting the amount to decimalfunction convertCrtoDecimal(\$amount) {     \$Arraycheck = array("4"=>"K","5"=>"K","6"=>"Lacs","7"=>"Lacs","8"=>"Cr","9"=>"Cr");     // define decimal values     \$numberLength = strlen(\$amount); //count the length of numbers     if (\$numberLength > 3) {        foreach (\$Arraycheck as \$Lengthnum=>\$unitval) {            if (\$numberLength == \$Lengthnum) {               if (\$Lengthnum % 2 == 0) {                  \$RanNumber = substr(\$amount,1,2);                  \$NmckGtZer = (\$RanNumber+\$RanNumber);                  if (\$NmckGtZer < 1) {                       \$RanNumber = "0";                  } else {                     if (\$RanNumber == 0) {                        \$RanNumber = "0";                  }              }      \$amount = substr(\$amount,0,\$numberLength-\$Lengthnum+1) . "." . \$RanNumber . " \$unitval ";    } else {         \$RanNumber = substr(\$amount,2,2);         \$NmckGtZer = (\$RanNumber+\$RanNumber);         if (\$NmckGtZer < 1) {             \$RanNumber  = 0;        } else {            if (\$RanNumber == 0)  {                \$RanNumber = "0";            }           }         \$amount = substr(\$amount,0,\$numberLength-\$Lengthnum+2) . ".". \$RanNumber . " \$unitval";          }     } } } else {     \$amount . "Rs";     } return \$amount; }  ?><!-- Call the function here --><?php \$amount=455000; //nummeric value in variable \$get_amount= convertCrtoDecimal(\$amount);echo 'Rs '.\$get_amount;?>`

Output: Rs 4.55 Lacs

Share: