Wednesday, March 28, 2012

Precision on Money data type

How do I set the precision on the money data type in SQL Server. I want it to display only 2 decimal places and get rid of any more than that id someone tries to insert more without throwing an error.

Example:

i input 10.5432

It makes it 10.54
automatically.

If this is not possible, can I at least put in an amount like 10.56 and not have the database automatically turn this into 10.5600

Please help::How do I set the precision on the money data type in SQL Server.

Tried the documentation? Mean, this is so obvious that I would look there first.

Let me quote from "money data type / overview":

::Monetary data values from -2^63 (-922,337,203,685,477.5808) through
::2^63 - 1 (+922,337,203,685,477.5807), with accuracy to a ten-thousandth of a monetary
::unit. Storage size is 8 bytes.

::I want it to display only 2 decimal places and get rid of any more than that id someone
::tries to insert more without throwing an error.

Welcome to programming. YOu have to do so in your input layer.

::If this is not possible, can I at least put in an amount like 10.56 and not have the database
::automatically turn this into 10.5600

You can us an insert / update trigger to round the values. I would normally handle this i n the business objects :-)|||Use decimal instead of money. You can exactly specify the precision and scale|||Thanks Dutch,... I appreciate that

No comments:

Post a Comment