What is the correct way to display rupee as paise with php?
eg,
552.25 rupee = 55225 paise
100.00 rupee = 1000 paise
1 Rupees is equal to 100 Paise (paise is an indian & pakistan currency)
So, you should used this formula
$paise=your_currency*100;
if you have simple 552.25 rupees
$rs=552.25;
$paise=$rs*100;
if you have 552.25 rupee. then
$rs=`552.25 rupee`;
preg_match('/([0-9]+\.[0-9]+)/', $rs, $matches);
$float_val= (float) $matches[1];
$paise=$float_val*100;
Simple, You can do it by this way.
Like below :
$rs = 100*100. " paise";
Output :
10000 paise
Related
I have a simple code in php and would like to add 3% on bitcoin value:
</PHP
$price = "0.00001000"
$price_format = str_replace(".", "", $price);
echo ($price_format + ($price_format / 100 * 3)); // 1030
?>
Return of my code:
1030
I need the return to be:
0.0001030
Does anyone know how I can perform this calculation by following the number of houses of the price?
You can use number_format when you multiply on the 3 percent to keep decimal places intact. Multiply price by 1.03 (3%) and specify 8 decimal places.
<?php
$price = 0.00001000;
$new_price = number_format($price * 1.03, 8);
echo $new_price;
Here's a link to number_format for more info:
https://www.php.net/manual/en/function.number-format.php
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 |
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
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];
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 .
use SUBSTRING_INDEX() to split values in mysql then update
UPDATE `table` SET `rupees`=SUBSTRING_INDEX(`amount`,'.',1),`paise`=SUBSTRING_INDEX(`amount`,'.',2)
Select substring_index('amount', '.', 1) as rupees, substring_index('amount', '.', -1) as paise;
I have a amount without 20% Tax in my country.. For example, 12,24 € it s without tax and 14,70 EUR it's with a TAX.
How can I add 20% to 12.24 EUR Amount in PHP?
My script is:
<? echo round($cena*(20/100)+$cena, 2);?>
But with this script is amount with TAX 14,40 EUR and in real it is 14,70 EUR.
Where is problem? And numbers with zero at start it don't calulcate.. It will show 0,- EUR.
Thanks.
Use this
$num = 12.24;
$percentage = 20;
$num += $num*($percentage/100);
$num = round($num, 1); // 4
$num = sprintf('%0.2f', $num);
echo $num;
As mentioned in comments, just multiply that number by 1.2. So:
<?php echo round($cena * 1.2, 2); ?>
if you use calculator to solve it, 14.70 is correct. to get 14.40
<?php echo round($cena * 0.18, 2); ?>
0.18 is 18%
But with this script is amount with TAX 14,40 EUR and in real it is 14,70 EUR. Where is problem?
The problem is with the format of your input, 12,24. It is treated as 12. This is probably because PHP expects the decimal point to be . and not ,.
SO I am going to integrate the dogecoin in to the my busniess website. My Products are avilable to purchase in EURO currency and for avilable to provide it in doecoin I need to convert the EURO to Dogecoin.
What I have DID: I have found the DOGECOIN API (https://www.dogeapi.com) in php. i have found that we can convert the DOGECOIN in BTC or USD. Using this :
https://www.dogeapi.com/wow/?a=get_current_price&convert_to=USD&amount_doge=1000
The above URL gives me the total USD from DOGE AMOUNT.output is : 1.13949000
My Question is : How Can i convert the EURO in DOGEAMOUNT ? I have search alot and not found any solution . please help. Thanks in Advance.
A bit messy but does the work (it uses another url to get exchanges for USD,EUR)
$doge2usd = file_get_contents("https://www.dogeapi.com/wow/?a=get_current_price&convert_to=USD&amount_doge=1");
echo sprintf("1 dogecoin => %f usd",$doge2usd); // 1 DOGE => USD 0.00115078
$eur2usd = file_get_contents("http://rate-exchange.appspot.com/currency?from=EUR&to=USD");
$j = json_decode($eur2usd,TRUE);
$doge2eur = $doge2usd * (1 / $j["rate"]); // 1 DOGE => 0.00083941557920536 EUR
echo sprintf("<br>1 dogecoins => %f euro, 5 dogecoins => %f euro",$doge2eur,$doge2eur*5);
$eur2doge = 1 / $doge2eur; // 1 EUR => DOGE 1197.29
echo sprintf("<br>1 euro => %f dogecoins, 5 euro => %f dogecoins",$eur2doge,$eur2doge*5);
The dogeapi.com API can only give you the exchange rate in BTC or USD. To get the exchange rate from XDG (is that the inofficial three-letter-code for Dogecoin? Let's just assume that) to EUR, you'll have to take two steps:
Get the exchange rate from XDG to USD.
Get the exchange rate from USD to EUR.
For the first one, we have DogeAPI. For the second one, I'm going to use Yahoo's API.
<?php
// how much is 1 dogecoin worth in USD?
$xdgusd = (double)file_get_contents("https://www.dogeapi.com/wow/?a=get_current_price&convert_to=USD&amount_doge=1");
// how much is 1 EUR worth in USD?
$yahoo_result = json_decode(file_get_contents("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20=%20%22EURUSD%22&format=json&env=store://datatables.org/alltableswithkeys&callback="));
$eurusd = (double)$yahoo_result->query->results->rate->Rate;
// how much is 1 dogecoin worth in EUR?
$xdgeur = $xdgusd / $eurusd;
echo "Doge in USD: " . $xdgusd . "\n";
echo "EUR in USD: " . $eurusd . "\n";
echo "Doge in EUR: " . $xdgeur . "\n";
This prints:
Doge in USD: 0.00113941
EUR in USD: 1.3713
Doge in EUR: 0.00083089768832495
Please note that this example doesn't cover details like bis/ask spread. Also, in a real system, you shouldn't query the web services with every request, but cache the result on your machine. And check if you got sane values back from the APIs.
I'm trying to use money_format in PHP to get this result: $100,000.00 USD if that is possible.
Here is what I have:
$cost = 100000;
$usd = money_format('%i', $cost);
This is what I get:
USD 100,000.00
What I would like is:
$100,000.00 USD
I may be adding other currencies later, so if the solution breaks the general utility and l10n of money_format then I won't use it and will just use the default value.
i prefer number_format()
$usd = '$'.number_format($number, 2, '.', ',').' USD';