11

I need to be able to store numbers like 3.5 in my table. So I've used the decimal type field. But if I enter 3.5 it round it up to 4. Am I being stupid or is it not the point of decimal to have a decimal point?

5
  • Why you do not use FLOAT, And if You need to round always numbers to 0.0 or 0.5 take look at this thread Commented Apr 6, 2010 at 8:30
  • yup that worked, I just though FLOAT was for massive numbers. Thinks I need to get my head around data types again. thanks adopilot! Commented Apr 6, 2010 at 8:34
  • @Jonesy - just make sure you understand the difference between FLOATs and DECIMALs as they are not the same. FLOAT is approximate: msdn.microsoft.com/en-us/library/ms173773.aspx vs DECIMAL reference: msdn.microsoft.com/en-us/library/ms187746.aspx Commented Apr 6, 2010 at 8:39
  • 2
    Can you post the full definition of the decimal column (i.e. the scale and precision you've used) e.g. DECIMAL(10, 2) - 10=precision, 2=scale. Also, how are you entering the number - into a UI? In an SQL statement? Could you post that up too? Commented Apr 6, 2010 at 8:41
  • 1
    Float is a very bad idea if you plan to do math onthe value. It will cause rounding errors as it is not an exact value. Very bad recommendation. Commented Apr 6, 2010 at 14:06

1 Answer 1

16

You need to declare it like decimal(18,3) to specify the number of digits after the point.

In case you are using stored procedure parameter also must have precision specified next to decimal, e.g. decimal(18,3)

Sign up to request clarification or add additional context in comments.

2 Comments

yeah it was declared as decimal(18,3). Not sure why I rounded it.
How did you put data? Maybe you are using stored procedure - than parameter also should have type decimal(18,3), not just decimal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.