Best data type for currency - asp.net & sql?
-
What is the best way to define money such that sql server and asp.net agree? I have defined money in my sql tables as 'money' and values are stored with 4 places after the decimal point. In asp.net I'm using CompareValidator with DataTypeCheck of type 'currency'. This is raising a problem for me because asp.net permits only two places after the decimal point and throws up a validation error for money values i.e. because they have 4 places after the decimal point. I would like to define money as having 2 places after the decimal point. How can I achieve this? Thanks Majella
-
What is the best way to define money such that sql server and asp.net agree? I have defined money in my sql tables as 'money' and values are stored with 4 places after the decimal point. In asp.net I'm using CompareValidator with DataTypeCheck of type 'currency'. This is raising a problem for me because asp.net permits only two places after the decimal point and throws up a validation error for money values i.e. because they have 4 places after the decimal point. I would like to define money as having 2 places after the decimal point. How can I achieve this? Thanks Majella
Use a regex validator instead and validate for ^([0-9](\.{0,1})([0-9]{0,4}))$ If you are storing 4 dp in the database, then your users may want to see all four at some point, so you might want to use a decimal datatype in .net and have some sort of formatting function for the front end.