How to change a price string in php


I'm having problems printing the price of my products so I want to change it, I mean I do my sql query

SELECT * FROM sinventario,as_precios WHERE sinventario.FI_CODIGO = as_precios.FI_CODIGO 

I save my data in an array and print it

  while ($filas = $db->recorrer($sql)){
            $FI_PRECIO= $filas['FI_PRECIO'];
    echo $PRECIO1;

but I print the price like Bs. "8221.85" and what I want is for me to print it like that Bs. "8.221,85"

asked by alexander123 31.05.2016 в 20:37

2 answers


Assuming that the value obtained is a number, you can use the number_format function to use the separators you want.

I also see that you are apparently doing echo to an undefined variable, so I will assume that you print $FI_PRECIO .

while ($filas = $db->recorrer($sql)) {
    $FI_PRECIO = number_format($filas['FI_PRECIO'], 2, ",", ".");
    echo $FI_PRECIO;
answered by 31.05.2016 / 20:45

Here what you can do from MySQL is to format it in this way:


And this will give you back 12,347

answered by 31.05.2016 в 20:47