我在Excel中有以下一組計算,我希望能夠在存儲過程中使用。SQL浮點精度限制爲6位數
的Excel
CellA: 45/448.2 = 0.100401606425703
CellB: 1-CellA = 0.899598393574297
CellC: 1-CellB = 0.100401606425703
CellD: CellC * 448.2 = 45.000000000000000
在SQL我做了以下內容:
declare @a decimal(18,15) = 45/448.2
declare @b decimal(18,15) = [email protected]
declare @c decimal(18,15) = [email protected]
declare @d decimal(18,15) = @c * 448.2
我也試圖在一行
declare @e decimal(18,15) = (1-(1-(45/448.2)))*448.2
運行計算時,我返回值SQL給我以下內容:
@a: 0.100401000000000
@b: 0.899599000000000
@c: 0.100401000000000
@d: 44.999728200000000
@e: 44.999728200000000
我試過調整SQL中小數的精度,但是我沒有任何區別,它只返回小數的前6位數。
運行公式時,Excel是否做了任何優化?
任何想法?
試試,說,'選擇45/CAST(448.2 AS DECIMAL(18,1))''。 [這裏的鏈接](http://stackoverflow.com/a/5385417/73226)告訴你分區結果數據類型的規則。 – 2013-04-08 16:03:43
@MartinSmith確實給了我一個更完整的@a小數,儘管我的回答是45.000000000000085你能解釋爲什麼嗎? – ScampDoodle 2013-04-08 16:07:28
這是從前面的答案,我懶得重現上面的兩個鏈接解釋。 e1/e2給出p = p1-s1 + s2 + max(6,s1 + p2 + 1),s = max(6,s1 + p2 + 1)'。如果'p'將是'> 38'然後's'被截斷在''6 – 2013-04-08 16:09:44