Search code examples
phpmysqlmoney-format

How to get rupees and paise in separate columns from the amount


The database value for my project will be TOTAL AMOUNT like "1500.45". What I want is to separate the column for Rupees & Paise. 1500 should be under Rupees column, and paise 45 should be under paise column. How to do that?

Output should be like this

|amount |       | rupees | paise |
|1500.45|   ==> | 1500   | 45    |

Solution

  • If you need two need for two decimal points then use the following code :

    $amount = 1500.45; // if it is a string then convert it into decimal
    $rupee = floor($amount);
    $paise = (int)($amount - $rupee)*100; // and set pricision two
    echo $rupee.'<br/>';
    echo $paise;
    

    and if it string or decimal any type then you can use the code as follows :

    $amount = 1500.45;
    $rupee = explode('.',$amount)[0];
    echo $rupee.'<br/>';
    echo explode('.',$amount)[1];