开发者

Cast as decimal not giving me correct results

开发者 https://www.devze.com 2023-01-06 19:56 出处:网络
I get a result of0.00000 from the following cast Secs_in_month = 2592000 total_fault_time_sum = 99 cast(((Secs_in_Month - total_fault_time_sum) / Secs_in_Month) as decimal(18,5)) AS availability

I get a result of 0.00000 from the following cast

Secs_in_month = 2592000
total_fault_time_sum = 99

cast(((Secs_in_Month - total_fault_time_sum) / Secs_in_Month) as decimal(18,5)) AS availability

the result should be 0.99996

any ideas on what I am doing wrong here ?

Many开发者_开发知识库 thanks


Cast it before division:

cast((Secs_in_Month - total_fault_time_sum) as decimal(18,5)) / Secs_in_Month AS availability

Otherwise, you're still doing integer division, and just casting the result.

0

精彩评论

暂无评论...
验证码 换一张
取 消