I want two digits after decimal.
cast(B.Bweight as decimal(10,2))/cast(C.iWeight as decimal(10,2))*100 [Percentage]
currently i am getting below result
0.9021512838300
but i want
0.90
I want two digits after decimal.
cast(B.Bweight as decimal(10,2))/cast(C.iWeight as decimal(10,2))*100 [Percentage]
currently i am getting below result
0.9021512838300
but i want
0.90
The resulting data type when you perform an operation on two decimal values is a complicated story, and I don't remember the rules by hart. But as you have experienced, dividing two decimal(10,2) values does not result in a new decimal(10,2) value.
I would write this as
cast( cast(B.Bweight as float)/cast(C.iWeight as float)*100 as decimal(10,2)) AS [Percentage]
The reason I would cast to float before the division is that this the best accuracy for the division as such. But depending on the actual data types of the Weight columns, this may be an over kill. The important is that you need to cast the final result to decimal(10,2).
14 people are following this question.
Year and Month aggregation in same Pivot table in SQL Server
SQL Server Query for Searching by word in a string with word breakers
How to show first row group by part id and compliance type based on priorities of Document type?
Query to list all the databases that have a specific user
T-sql query to find the biggest table in a database with a clustered index