Format decimal places directly in the SQL command in Firebird

Asked

Viewed 180,098 times

13

I have a table ESTOQUE containing a field called QTDE, this field has 3 decimal places.

What would be the command to return directly from SQL formatted with 3 houses? Because the integer values are returning without the houses.

I use: Firebird 2.0 / Field: Decimal(15.3)

  • Are you saying that even when you make a SELECT * FROM ESTOQUE, the integer values in the field QTDE do not show .000?

  • From what I understand, you get in your bank manager values with the decimals, idependente to be with zeros or not, but in the client, when the value is integer, does not return houses.. is that it? If I understand correctly, the problem is the customer. Depending on the programming language used in your program to display the database data on the client side, it is necessary to format the value in the form of a string to display it correctly. Could give more details of your application to help?

7 answers

14

Try it like this:

SELECT cast(seu_campo AS NUMERIC(15,3)) FROM sua_tabela

I believe your intention is to show this on the screen so try it like this:

select cast(seu_campo as varchar(10)) from sua_tabela
  • Ok... but when the record is integer ex. 65 it does not turn to 65,000

  • Then try as follows: select cast(Qtd as varchar(10)) from stock

  • In Firebird, NUMERIC and DECIMAL are exactly the same. http://www.firebirdfaq.org/faq340/

  • 1

    Perfect.. I did the test with Varchar and it worked blezinha.. select cast(you_campo as varchar(10)) from your_table

  • thanks guys. thank you all!

  • Please Lucioam then mark as answered your question to help other users.

  • @Mattjohnson As far as I can remember that’s not entirely true. http://www.firebase.com.br/fb/artigo.php?id=2019

  • @Yes, I found some answers with contrary information.

  • @Mattjohnson sent an email to the Firebird FAQ staff mentioning the documentation

Show 4 more comments

5

select format(1.003, 'N', 'pt-br') = 1.00
select format(1.03, 'G', 'pt-br') = 1.0300
select format(1.489, 'C', 'pt-br') = R$ 1,49

  • Wagner, welcome to [en.so]. If you can explain a little better your answer will be of great help.

4

I did the select using:

CAST(CAST(a.CAMPO AS DECIMAL(18,6)) AS VARCHAR(30))

Worked perfectly.

3

Configured Firebird 2.0 here on my system, I created a table with QTDE, with DECIMAL(15,3). I have inserted 4 numbers, 10.521, 11.11, 65, and 65.88. After that I made SELECT * FROM tabela;, and returned with all the necessary houses, including 65.000.

Is it some configuration with the client you are using to do SQL? I used Database Workbench v4.4.3 Lite, Firebird Edition to do everything.

3

Convert Varchar to decimal, before you have to convert comma per point for the command to work:

cast( replace(p.valor_venda,',','.') as decimal(18,6))

Do it the way it works above...

2

Example in the case of a VIEW that I created:

ALTER VIEW vw_Saldos_Clientes as
Select C.ID_Cliente as ID, C.Nome_Cliente as Cliente,
format(C.Saldo, 'C', 'pt-br') as Saldo
FROM dbo.tbl_Clientes C (NoLock)

Upshot:

1   Rafael Vilaça       R$ 5.720,00
2   Fernanda Fabiana    R$ 2.600,00
3   Renata Mendonça     R$ 2.600,00
4   Lucas Rosa          R$ 2.600,00
5   Luis Fernando       R$ 2.600,00

The command "format(C.Saldo, 'C', 'pt-br')" format the value Money for the currency type of Brazil (R$)

I hope I was clear... Thank you...

  • 1

    What version of FB? Are you sure it’s not UDF?

-1

Good friend I did this way, I looked up to where I wanted, then I feed the bank again with the value I sought.

inserir a descrição da imagem aqui

update oepd set 
       pesliq= (SELECT cast(pesliq AS NUMERIC(15,3))as valor FROM e210epd as ori 
                where ori.numemb=oepd.numemb and ori.codlot=oepd.codlot) 
from e210epd as oepd where numemb=14242 

inserir a descrição da imagem aqui

  • 1

    Dear Arlindo, your answer is a little complicated to understand, your suggestion is to update the data? But the AP just wants to return the values, I see no sense for this, could review the answer and explain the reasons better?

Browser other questions tagged

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