i have an algorithym that gives back a number with a decimal point (I.E. ".57"). What I would like to do is just get the "57" without the decimal.
I have used eregi_replace and str_replace and neither worked!
$one = ".57";
$two = eregi_replace(".", "", $one);
print $two;
$one = '.57';
$two = str_replace('.', '', $one);
echo $two;
That works. 100% tested. BTW, all ereg(i)_* functions are depreciated. Use preg_* instead if you need regex.
Method Result Command
x100 57 ((float)$one * 100))
pow/strlen 57 ((float)$one * pow(10,(strlen($one)-1))))
substr 57 substr($one,1))
trim 57 ltrim($one,'.'))
str_replace 57 str_replace('.','',$one))
Just shwoing some other methods of getting the same result
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With