Currency Format

0

To be complete could not enter with a FORMAT (Value, 2) even in CONCAT?

SELECT * , CONCAT('de ', Valor, ' por ', desconto) AS promocao  
FROM (SELECT Valor, Valor - Valor * 20/100 AS desconto  
FROM comissao 
ORDER BY comissao.Valor DESC) t; 

On the page the result of CONCAT's "promotion" column is unformatted, for example: "of 14230 by 11384 'would be better 14,230.00 and the discount of 20% would be 11,384.00.

    
asked by anonymous 07.12.2016 / 02:14

1 answer

2

You can use the FORMAT function as follows:

SELECT t.*,
       CONCAT('de ', FORMAT(t.valor, 2, 'de_DE'), ' por ', FORMAT(t.desconto, 2, 'de_DE')) AS promocao  
  FROM (SELECT c.Valor as valor,
               c.valor - c.valor * 20/100 AS desconto
          FROM comissao c
         ORDER BY c.valor DESC) t; 

The result of the promotion column would be:

  

of 14,230.00 for 11,384.00

About function:

  

FORMAT(X,D[,locale])      

Formats the number X to a format like '#, ###, ###. ##', rounded to D decimal places, and returns the result as a string. If D is 0, the result is no decimal point or fractional part.

     

The optional third parameter enables the locale to be specified as the decimal point, thousands separator, and grouping between separators. .... If no locale is specified, the default is 'en_US'.

Or in free translation:

  

Format an X number for a format '#, ###, ###. ##' rounding to the decimal places D, and returns the result as a string. If D is 0, the result has no decimals.

     

The third (optional) parameter enables the locale specification used to determine the decimal separator, the thousands separator, and the grouping between result separators. .... If no location is specified, the default is 'en_US'.

I used the de_DE location because Germany uses the international standard that is the same as the one we used and the pt_BR did not have the thousands separator.

    
07.12.2016 / 03:27