Convert Integer to Decimal in SQL

Asked

Viewed 1,166 times

2

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

1 answer

4


To return the formatted Mysql value, do so:

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

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

<?php
$valor = 12345;
$preco = 'R$' . number_format($num, 2, ',', '.'); // R$ 12.345,00
  • Friend, I want to make this direct conversion in sql query

  • @Mathdesigner47 I edited the answer.

  • 2

    @Mathdesigner47 Then you should remove the [tag:php] from your question.

  • Buddy, whatever you want

  • @Mathdesigner47 if the answer is correct, then mark it with the "green" sign below the dots arrow.

Browser other questions tagged

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