All Forums Database
teradatatester 69 posts Joined 01/10
10 Jul 2015
Why does my percentage have no values after the decimal?

Why does my percentage have no values after the decimal?

1

2

3

4

5

GOOD    BAD MY_PERCENT  DESIRED_RESULT

38652   614 98          98.436306219

3402    37  98          98.924105845

3545    36  98          98.994694219

3525    39  98          98.905723906

I am trying to calculate the percent from two numbers that are INT data type.
Why does my percentage have no values after the decimal?
My SQL:
SELECT
  STATE
, GOOD
, BAD
, CAST( (GOOD*100/(GOOD+BAD)) as DECIMAL(18,9))  as MY_PERCENT
FROM MY_TABLE
ORDER BY STATE

 

teradatatester 69 posts Joined 01/10
10 Jul 2015

Why should I have to convert the INT to DEC before the percent calculation is performed?

Fred 1096 posts Joined 08/04
11 Jul 2015

Why? Because by definition when you divide one integer value by another integer value, the result is truncated to an integer.

You must sign in to leave a comment.