Turn 2600 into 26.00 in PHP?

Asked

Viewed 114 times

-5

I will have values like 2600 or 15000 and need to put as 26.00, 150.00, etc. How can I do this in PHP ? With the function number_format it puts wrong (in my case) as 2600,00 or 15,000,00. How can I do ?

  • 2

    Explain better what you want, because it’s very basic math, just divide by 100, then you do what you want.

  • So simple né @bigown. I made this split by 100 and it worked :)

  • Violating the logic.

1 answer

1

Do the following:

<?php
$number = "15000";
echo number_format($number, 0, ',', '.');
?>

So he will return: 15,000

  • 1

    This is wrong man, the number must come in the correct amount and you will only add the decimals using the same number_format. If it is coming with zero more you can consider this a bug.

Browser other questions tagged

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