Lodewijk
Lodewijk

Reputation: 2391

SQL: Decimal precision as specified by user

In C#, the decimal type 'remembers' the precision of the original number:

decimal.Parse("090,12300").ToString() == "90,12300"
decimal.Parse("090,123").ToString() == "90,123"
decimal.Parse("090,0").ToString() == "90,0"
decimal.Parse("90").ToString() == "90"

For business reasons (*), this precision is important for us, so we want persist this in the database (SqlServer). Is there an SQL-datatype (except varchar) that behaves in the same way as the c# decimal?

(*) The users want to see the exact number as entered in the application. For example: some scales are more precise than others. This means that 12.5 has another meaning than 12.50 in this scenario.

Upvotes: 0

Views: 105

Answers (1)

Dennis C
Dennis C

Reputation: 24747

Use two columns, one for the value itself, and second one for number of digits after point.

What you will need is a function that format your value to string, with padding zero until enough number of digit.

Upvotes: 1

Related Questions