1

I got this php code. I am new in php and this is a very simple question. As you can see in the amount, i am getting post from a before page. My problem is the following If the user add 300USD then payment provider understand it as 3USD. If user insert 3000USD payment provider understand it 30USD. I want to add two extra zeros by default. How can I do it?

$params = array(
    'site_id' => '231321',
    'amount' => $_POST[amount],
    'currency' => $_POST[currency],
    'site_login' => $current_user->user_email,
    'email' => $current_user->user_email,
    'external_id' => $externalid ,
);
RamC
  • 1,287
  • 1
  • 11
  • 15
Elpidios
  • 29
  • 6
  • 2
    Take a look at [string concatenation](https://stackoverflow.com/questions/11441369/php-string-concatenation), that should help. – Filnor Dec 18 '17 at 09:01
  • What payment provider are you using? There should be an explanation to that. It seems that the payment provider automatically translates the last 2 remaining digits as decimals. I've seen it happen many times. – Gene M Dec 18 '17 at 09:05

2 Answers2

0

You can multiply the amount by 100 to obtain the result.

Example

$amount = $_POST[amount] * 100;

Code

$params = array(
    'site_id' => '231321',
    'amount' => $_POST[amount] * 100,
    'currency' => $_POST[currency],
    'site_login' => $current_user->user_email,
    'email' => $current_user->user_email,
    'external_id' => $externalid ,
);
RamC
  • 1,287
  • 1
  • 11
  • 15
0

Are you able to access the $params array before you use it in the following steps? If so, why don't you just modify the content?

$params['amount'] *= 100;

You should check though that the contents really is a number, etc.

taalas
  • 395
  • 3
  • 16