Reputation: 3
I'm kind new to SQL world and just started doing queries.
In this case, I'm calculating how much % a number represents of that other number.
This is how I'm doing:
Percentage = ROUND(((NULLIF(SUM(value_1), 0)) / NULLIF(SUM(value_2),0) * 100), 2),
Even if I use ROUND(), the results still the same, they will give me 6 digits after comma:
100.020000
56.800000
-33.330000
100.000000
42.490000
Is there any way to format these numbers with just 2 digits after comma?
Thank you!
Upvotes: 0
Views: 910
Reputation: 686
Assuming you use sql server, you can convert your result :
Percentage = Convert(numeric(10, 2), ROUND(((NULLIF(SUM(value_1), 0)) / NULLIF(SUM(value_2),0) * 100), 2))
Or Cast it :
Percentage = Cast(ROUND(((NULLIF(SUM(value_1), 0)) / NULLIF(SUM(value_2),0) * 100), 2) AS numeric(10, 2))
Upvotes: 0