The difference between money and integer data types

what is the difference between money and bigint data type in sql server?

+3
source share
2 answers

Range / Accuracy

bigintrange from -9,223,372,036,854,775,808to9,223,372,036,854,775,807

moneyrange from -922,337,203,685,477.5808to922,337,203,685,477.5807

storage

They both take 8 bytes of memory and are stored as large integers, the only difference is that SQL Server understands that there are four right most digits after the decimal point.

If you do

declare @m money = 1.2345
declare @b bigint = 12345

select cast(@m as BINARY(8)), cast(@b as BINARY(8))

You see that the repository is the same.

------------------ ------------------
0x0000000000003039 0x0000000000003039

Behavior

However, the data type moneydoes not behave as if you just used it bigintyourself. Calculations with money should be avoided , but they are even more accurate than similar integer division.

declare @m money = 1.9999, @m2 money = 1

select @m/@m2 /*Returns 1.9999*/

declare @b bigint = 19999, @b2 bigint = 10000

select @b/@b2 /*Returns 1*/
+9
source

, ; bigint , money .

bigint --------------

44 () ------- 44 () db 44.0000

4.4 () ---- 4.4 () db 4.4000

0

All Articles