Control Freak
Control Freak

Reputation: 13233

How come numeric scale returns an additional digit

I have a column that is varchar, and I am trying to convert it to numeric(8,2) to return it like this 1.00, but its returning it like this instead 1.000

Example:

 Select 
   Convert(numeric(8,2),WholesaleCost) * 2.2)
 FROM Table

This Returns 50.900

Seems like when I reduce the scale to numeric(8,1) instead of numeric(8,2) it returns how I want it, which is 50.90

Does anyone know why its doing this? Why its adding an additional scale digit to the result? Shouldnt it be 50.9 when i do numeric(8,1)?

Upvotes: 1

Views: 112

Answers (1)

Martin Smith
Martin Smith

Reputation: 453395

Because you are doing numeric(8,2) * numeric(2,1) and the resultant datatype is numeric(11,3)

When multiplying two numeric numbers e1 * e2 the result has precision p1 + p2 + 1 and scale s1 + s2 as per Precision, Scale, and Length

Upvotes: 1

Related Questions