Which datatype should I be using to give me a number with 2 decimal places?

I currently have the following line:

command.Parameters.Add("@miles", SqlDbType.Decimal, 2).Value = miles; 

and I am not sure what SqlDbType.Decimal, 4 means in terms of decimal places?

Will that allow the following

123.32 123321.67 

and not allow numbers like

123 123.123321 543345.5434523 324.1 
4

2 Answers

For decimal you need to specify both the precision and scale of the parameter.

You do this by constructing the parameter (using new) and adding it.

The two last constructor overloads in the SqlParameter MSDN page have arguments for precision and scale.

Hello you can try with Scale in order to format your parameter

 SqlParameter parameter = new SqlParameter("miles", SqlDbType.Decimal); parameter.Scale = 2; //The number of positions 
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy