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
Why should I have to convert the INT to DEC before the percent calculation is performed?
Why? Because by definition when you divide one integer value by another integer value, the result is truncated to an integer.