Page 1 of 1

String replace

Posted: Fri Jul 21, 2017 5:28 am
by asai
Hi,

I am trying to make a string to a int.

Heres an example:

Code: Select all

<?php
$a1 = '567,89';
$a1 = (int)str_replace(',', '.', $a1);
echo $a1;
?>
Expected output is 567.89. However the output is 567.
How can I get the result I want?

Re: String replace

Posted: Fri Jul 21, 2017 7:18 am
by requinix
Integers don't have fractional parts. That's what makes them integers.

Try (float) instead.

Re: String replace

Posted: Fri Jul 21, 2017 7:28 am
by asai
Yes ofcource. I should have known this.
Done it a lot of times in java programming.
Thanks for the help. :)