PHP - Convert string to int

Asked

Viewed 310 times

-2

I’m trying to convert the string '450,000.00' in int to insert into the database. But when I do cast or use intval(), the value returned goes to 450 only. In case I need the 450.000.

How else could I do it?

  • love php so number_format($numero, '2', ', '')

  • 1

    First you need to remove the dots, then swap comma for dot, and only then convert.

1 answer

-5

Without delay the most useful nut solution:

$number = "450.000,00";
$numbers = explode(',', $number);
$numberss = explode('.', $numbers[0]);
$string = $numberss[0].$numberss[1].$numbers[1];
  • 4

    I voted -1 because the solution is really bad. It does explode unnecessarily and basically only works for the example presented in the question. If the input was "450000,00" or "1.450.000,00" would no longer work.

  • 1

    "Pig" I wouldn’t rank, but it’s useless.

  • haha, leave it there the question is duplicated found a lot of solution!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.