search

Home  >  Q&A  >  body text

Thousand separator PHP

I extracted this $number = 100000.5; from the database.

What I need is to set the format to 100.000,5

str_replace number_format I guessed it.

My replacement worked perfectly,

echo str_replace('.', ',', $row['anskaf_sum']);

(return: 100000,5) But when I add number_format I somehow fail

number_format($row['anskaf_sum'] , 0, ',', '.');

return

101

I've tried a few other approaches but I can't seem to get close to the answer I need

Thanks.

P粉848442185P粉848442185390 days ago641

reply all(1)I'll reply

  • P粉151720173

    P粉1517201732023-11-08 00:31:23

    Are you sure your $row['anskaf_sum'] doesn't contain values ​​you don't expect? because:

    <?php
            $number = 100000.5;
            echo number_format($number, 1, ",", ".");
    ?>

    ...this will return the result you want: 100.000,5

    reply
    0
  • Cancelreply