Skip to main content
Inspiring
May 20, 2013
해결됨

remove decimal out of an equation to send to a payment gateway

  • May 20, 2013
  • 1 답변
  • 930 조회

i have a value that currently has shows a decimal

@$amount = $_POST['amount'];

i need the decimal to show until the variable $amount is sent to the payment gateway

what is the best way to remove the decimal from the variable

so a value of e.g

250.59

will be sent as 25059

thanks

이 주제는 답변이 닫혔습니다.
최고의 답변:

Replace decimal "." with nothing by using str_replace() funtion.

$amount = str_replace(".","",$amount);

best,

Shocker

1 답변

답변
May 20, 2013

Replace decimal "." with nothing by using str_replace() funtion.

$amount = str_replace(".","",$amount);

best,

Shocker

Inspiring
May 21, 2013

ok thanks

would multiplying by 100 also work?

May 21, 2013

would multiplying by 100 also work?

$amount = "250.59";

echo $amount*100;

// 250.59*100 displays 25059

$amount = str_replace(".","",$amount);

echo $amount*100;

// 25059*100 displays 2505900

Your original question specifically asked how to remove a decimal, not how to multiply a variable by 100.

best,

Shocker