I have two string : '99.00'
and '99.154'
,
I would like to convert '99.00'
to 99
and '99.154'
to 99.154
How can I do that ?
Asked
Active
Viewed 232 times
-2

gp_sflover
- 3,460
- 5
- 38
- 48

Nguyen Nhut Tien
- 129
- 13
-
1Does this answer your question? [How do I convert a string to a number in PHP?](https://stackoverflow.com/questions/8529656/how-do-i-convert-a-string-to-a-number-in-php) – Code4R7 Sep 15 '20 at 08:18
-
Does this answer your question? [Convert a string to a double - is this possible?](https://stackoverflow.com/questions/2540078/convert-a-string-to-a-double-is-this-possible) – Agnohendrix Sep 15 '20 at 08:18
1 Answers
0
PHP has two build-in functions for that.
If you want to convert String -> Integer, you can/should use:
<?php
echo intval('90.00'); //returns 99
?>
If you want do dig deeper, i will Link you both Docs at the bottom.
But.. if you want to convert String -> Double, you can/should use:
<?php
echo floatval('90.154'); //returns 90.154
?>
In additon to floatval you can use doubleval, its an alias for floatval
And here the Links:
intval()
floatval()
doubleval()

Yannick
- 177
- 2
- 13
-
How to I determine when use intval or floatval ?, because value from a string array. – Nguyen Nhut Tien Sep 15 '20 at 08:40
-
You could check if it is an integer with the following build-in function. `is_int(*YOUR_VALUE*)`. This Function returns true or false. – Yannick Sep 15 '20 at 08:58