Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is more suitable for prices calculations in Firebird: decimal or numeric?

Tags:

sql

firebird

In Firebird DB: I read about the difference between numeric and decimal but still not sure Which is more suitable for prices calculations: decimal or numeric without rounding numbers?

like image 428
zac Avatar asked Dec 30 '12 12:12

zac


2 Answers

The implementation for both NUMERIC and DECIMAL are almost identical in Firebird. The Interbase 6.0 Data Definition Guide says there is a subtle difference (for NUMERIC precision is exactly as declared, for DECIMAL the precision is at least equal to declared). According to The Firebird Book by Helen Borrie there is only a difference for numbers with a precision of less than 5 as a NUMERIC of precision 1-4 is mapped to a SMALLINT while a DECIMAL of precision 1-9 is mapped to INTEGER. This book also remarks that both NUMERIC and DECIMAL conform to the behavior of the SQL-92 type DECIMAL.

So with that said, I'd advise to go for DECIMAL, as its behaviour conforms to that defined in the SQL standards and therefor holds less surprise for people unfamiliar with Firebird, but who do understand the standard behaviour.

like image 87
Mark Rotteveel Avatar answered Oct 06 '22 19:10

Mark Rotteveel


They're both equally suitable for price calculations. But there will always be certain kinds of calculations that require rounding, no matter which of these you use.

Decimal is the more flexible of the two.

like image 44
Mike Sherrill 'Cat Recall' Avatar answered Oct 06 '22 18:10

Mike Sherrill 'Cat Recall'