There are a few ways that you can convert decimal to percentage in PHP.
Option 1. Isolate number and divide it by 100
- Use str_replace() method to remove percentage sign from string
- Divide number by 100
Here is an example below:
$percent = '25%';
$decimal = str_replace('%', '', $pct) / 100;
var_dump($dec);
Option 2. Place percentage string in floatVal() method and divide by 100
The floatVal() method convert a string to a float, even if they are other characters with the numbers.
Here is an example below:
$decimal = floatval("25%") / 100;
var_dump($decimal);