How to round a number in Firebird?

Viewed 242

I have an issue when casting in Firebird

with data as (
  select article_name || cast(quantity as varchar(50)) as quantity, PREORDER_ID as PID
  from preorder_item
)

SELECT * FROM DATA

Is providing me with

| QUANTITY                      | PID                                  |
|-------------------------------|--------------------------------------|
| Mohnbrötchen1.000             | f1cf767c-5218-4ad2-8b92-1105b7690d9a |
| Sesambrötchen1.000            | f1cf767c-5218-4ad2-8b92-1105b7690d9a |

Would it be possible to have only 1 or 2 instead of 1.000?

2 Answers

Try this: (round)

with data as (
  select article_name || cast(round(quantity, 0) as varchar(50)) as quantity, PREORDER_ID as PID
  from preorder_item
)

SELECT * FROM DATA

Besides using ROUND as suggested by Stéphane Millien, you can also cast QUANTITY to INTEGER:

select article_name || cast(quantity as integer) as quantity, PREORDER_ID as PID
from preorder_item
Related