-2

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 ?

gp_sflover
  • 3,460
  • 5
  • 38
  • 48
  • 1
    Does 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 Answers1

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