以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 求比例请教 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=60823) |
||||
-- 作者:hbhb -- 发布时间:2014/12/1 21:02:00 -- 求比例请教 甜大师:好!如示例 请问如何比例,且最后比例之和要等于1,前面各项小数保留两位(四舍五入),差放在最后一项(行)的代码? 劳驾帮忙写一下。谢谢!
|
||||
-- 作者:有点甜 -- 发布时间:2014/12/1 21:11:00 -- Dim sum As Double = Tables("表A").Compute("sum(销量)") For Each r As Row In Tables("表A").Rows r("比例") = Format(r("销量") / sum, "0.00") Next sum = Tables("表A").Compute("sum(比例)") If sum <> 1 Then Dim nr As Row = Tables("表A").AddNew() nr("比例") = sum - 1 End If |
||||
-- 作者:hbhb -- 发布时间:2014/12/1 21:27:00 -- 谢谢!如果不等于1,您是新增行,我的意思是修改最后一个需计算比例的数据行,或者是修改任何数据行的比例列的值,就是要保证比例和等于1? |
||||
-- 作者:有点甜 -- 发布时间:2014/12/1 21:32:00 -- Dim sum As Double = Tables("表A").Compute("sum(销量)") For Each r As Row In Tables("表A").Rows r("比例") = Format(r("销量") / sum, "0.00") Next sum = Tables("表A").Compute("sum(比例)") If sum <> 1 Then Dim idx As Integer = Rand.Next(Tables("表A").Rows.Count - 1) Dim nr As Row = Tables("表A").Rows(idx) nr("比例") += 1 - sum End If |
||||
-- 作者:hbhb -- 发布时间:2014/12/1 22:01:00 -- 谢谢!为何您写的代码简洁精练,我就不行,功夫如何锤炼,有何技巧,介绍一二? |