-3

I need to convert price to 12 digit number for bank payment gateway process

Example: 25.00 convert to 000000002500

how to do that

i keep price in integer format in database.

Thanks

  • Multiply the the example by 100 or remove the . then use [str_pad](http://php.net/manual/en/function.str-pad.php) ? This question has been asked on Stackoverflow a lot and I recommend next time you do some better research – IsThisJavascript Apr 05 '18 at 08:39
  • Hint: `str_pad(25.00*100 ,12 ,"0", STR_PAD_LEFT);` – Sunil Apr 05 '18 at 08:41

1 Answers1

1

You can use the sprintf function to do that, e. g.:

$printvalue = sprintf("%012d", $intvalue);

To print the price as the OP asked, you set $intvalue to an integer, as:

$intvalue = $decimalvalue * 100;
$printvalue = sprintf("%012d", $intvalue);
caylee
  • 921
  • 6
  • 12