我试图在sql中显示pi的估计值。我想我的估计是数字(12,11),但它只显示4位数字的总和,精度为3。如何格式化此代码?
declare @fNum as float
declare @yNum as float
declare @pi as float
declare @loopNum as int
declare @inCount as int = 0
declare @totalCount as int = 0
set @loopNum = 1000
declare @oDist as numeric
while @loopNum > 0
begin
set @totalCount +=1
set @fNum = rand () * 100 + 1
set @yNum = rand() * 100 +1
set @oDist = POWER(@fNum, 2.0) + Power(@yNum, 2.0)
if sqrt(@oDist) <= 100.00
set @inCount +=1
set @loopNum -= 1
set @pi = (4.0 *@inCount / @totalCount)
end
select @inCount AS 'IN', @totalCount as 'ALL',/* @fNum as 'f', @yNum as 'y', sqrt(@oDist) as 'Origin'*/ cast(@pi as numeric(7,6)) as 'Pi'
go
暂无答案!
目前还没有任何答案,快来回答吧!