Kalaivani M
Kalaivani M

Reputation: 1290

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    |

Upvotes: 0

Views: 4484

Answers (5)

Vini Dubey
Vini Dubey

Reputation: 71

Select substring_index('amount', '.', 1) as rupees, substring_index('amount', '.', -1) as paise;

Upvotes: 0

Balan
Balan

Reputation: 421

use SUBSTRING_INDEX() to split values in mysql then update

 UPDATE `table` SET `rupees`=SUBSTRING_INDEX(`amount`,'.',1),`paise`=SUBSTRING_INDEX(`amount`,'.',2)

Upvotes: 0

PHP Geek
PHP Geek

Reputation: 4033

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];

Upvotes: 1

Kalai Vani
Kalai Vani

Reputation: 21

simply using split comment to separate rupees and paise..

 <?

$RS=2300.75;

$df=split("[.]",$RS);

echo "rupees ".$df[0];
echo "<br>";
echo "paise ".$df[1];


?>

for more details see the link php code for rupees and paise

Upvotes: 2

Sanket
Sanket

Reputation: 99

Use explode() Function .

explode(".",your amount)

explode will separate your amount to get Rupees & Paise . You will get separated value in array using that array you can store bot values in separate columns .

Upvotes: 1

Related Questions