monu DevP
monu DevP

Reputation: 33

How can i convert Dollar into cents on stripes charge.php page?

This is my code

getting price from last page

$Voucher_value=mysqli_real_escape_string($con,$_POST['Voucher_value']);

 $charge = \Stripe\Charge::create(array(
        'customer' => $customer->id,
        'amount'   => $Voucher_value,
        'currency' => 'usd',
        'receipt_email' => $email
    ));
    $chargeAmount=$charge['amount'];
    $Custcurrency=$charge['currency'];

Upvotes: 1

Views: 1107

Answers (1)

Ywain
Ywain

Reputation: 17533

If you're always dealing with US dollars, or another currency with 2 decimal points, you can simply multiply by 100 and truncate the results to an integer:

$amount = intval($Voucher_value * 100);

Upvotes: 4

Related Questions