How to change a price string in php

3

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
source

2 answers

2

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
source
2

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

format("12347",2)

And this will give you back 12,347

    
answered by 31.05.2016 в 20:47