Convert Integer to Decimal in SQL

2

I have numbers in the database that are in full format. Ex: 12345 I want to convert it to the price format, in Reais. Ex: 12.345,00

    
asked by anonymous 05.02.2015 / 19:51

1 answer

4

To return the value formatted in MySQL, do the following:

SELECT CONCAT('R$ ', FORMAT(valor, 2));

If you want to edit the value in PHP, you should use the number_format function.

<?php
$valor = 12345;
$preco = 'R$' . number_format($num, 2, ',', '.'); // R$ 12.345,00
    
05.02.2015 / 19:53