如何以百分比(%)格式获取价值 [英] how to get value in percentage (%)format
本文介绍了如何以百分比(%)格式获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
@ Cte1_count ='2'
@ cte2_count ='500'
i想要Totalcount = 0.42%格式仅
即使我尝试过
(Cte1_count / cte2_count)* 100
但它的节目0只请帮帮我
解决方案
将一个转换为浮点数值
声明 @ Cte1_count INT = 2
声明 @ Cte2_count INT = 500
选择(@ Cte1_count / CONVERT( FLOAT , @ Cte2_count ))* 100
结果
- --------------------
0 。 4
( 1 行受影响)
试试这种方式
声明 @ Cte1_count int = 2
声明 @ cte2_count int = < span class =code-digit> 500
声明 @ dec < span class =code-keyword> decimal ( 6 , 2 )
SET @ dec =(CAST( @ Cte1_count AS Fl燕麦)/ CAST( @ cte2_count AS FLoat ))* 100
print @ dec
@Cte1_count='2'
@cte2_count='500'
i want Totalcount=0.42% format only
even i tried like
(Cte1_count/cte2_count)*100
but its show 0 only please help me
解决方案
Convert one for count into floating point numeric value
declare @Cte1_count INT = 2 declare @Cte2_count INT = 500 select (@Cte1_count/CONVERT(FLOAT, @Cte2_count))*100 result ---------------------- 0.4 (1 row(s) affected)
Try this way
declare @Cte1_count int = 2 declare @cte2_count int = 500 declare @dec decimal (6,2) SET @dec = (CAST(@Cte1_count AS Float)/CAST(@cte2_count AS FLoat))*100 print @dec
这篇关于如何以百分比(%)格式获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文