Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Which datatype to store money?

Author  Topic 

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2007-07-29 : 07:24:16
Hi,

I am writing a application that needs to store the cost/retail price for products.

Should I use:

decimal
float
numeric (if yes, what kind of precision??)
deciment (same as above)
money

Really confused here!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-29 : 07:46:26
Depend on your requirement. You can use numeric or decimal with 2 decimal places or money (4 decimal places). But you should not use float as it is an approximate value


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2007-07-29 : 12:46:18
I've seen someone use numeric 18,10
what does that mean?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-29 : 12:50:06
18 digits in total, 8 to the left of decimal point, and 10 digits to the right of the decimal point.

I would suggest using MONEY.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2007-07-29 : 16:17:00
Wierd, I don't see any reason why you would want 10 digits to the right ofthe decimal for a dollar amount!
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-07-30 : 03:14:29
"Wierd, I don't see any reason why you would want 10 digits to the right ofthe decimal for a dollar amount!"

Well, I agree its quite a lot of precision! But you might need more than just Dollars and Cents for Price Each (fractions of a cent perhaps?) and Sales Tax calculation.

Money has 4 decimal places, we use that. Be prepared to use ROUND to cut back to 2 decimal places after Sales Tax and LineTotal = Qty * PriceEach type calculations.

Kristen
Go to Top of Page

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2007-07-30 : 15:17:05
Yeah I will be calculating sales tax for sure.

So your expert opnion is money then eh? not numerical 18,n
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-07-30 : 15:19:27
"So your expert opnion is money then eh? not numerical 18,n"

Ah; if you want to call it an Expert Opinion I'll have to charge your $,000 for it to cover the cost of my liability insurance!!

But assuming you aren't going to sue me : Yeah, that's about the top-and-bottom of it.

Kristen
Go to Top of Page
   

- Advertisement -