从0相加若干个数,直到总合等于100
相加的数要保持降低趋势直到等于100
比如:0+9+8.5+8.2+7.4.......................=100;
而且每次相加的数字是无规律的,而且必须保持降低趋势
请问如何实现?
相加的数要保持降低趋势直到等于100
比如:0+9+8.5+8.2+7.4.......................=100;
而且每次相加的数字是无规律的,而且必须保持降低趋势
请问如何实现?
解决方案 »
- 在datalist 外方法中 控制 datalist里一个删除按钮的显示与隐藏状态!
- 在线等。关于windows2003 服务器的问题。(100)分
- 如何让单选按钮根据数据库的内容选中某一个。
- 请教关于硕思闪客精灵,我是菜鸟,别笑我啊!谢谢!
- 请大家谈谈在ASP.NET的开发中,都喜欢用什么表格和报表控件
- 一个dataset和rowfilter的问题
- ajax Response.Write excel的问题
- 安装VS.Net2003之前必须安装IE6的sp1吗?如果不安装会怎样?
- 十万火急!Help me!
- html内容用正则匹配指定内容
- asp.net生成动态.html页面
- 日期类型相减得到小时数
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;public partial class Default7 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
String strValue = String.Empty;
foreach (Decimal decItem in GetList())
{
strValue += decItem.ToString() + "+";
}
strValue = strValue.Substring(0, strValue.Length - 1)+"=100";
Response.Write(strValue);
}
} public List<Decimal> GetList()
{
List<Decimal> objList = new List<decimal>();
objList.Add(0); Decimal decValue = 0.0m;
while ((decValue = GetValue(objList[objList.Count - 1])) < 100.00m - GetSum(objList))
{
objList.Add(decValue);
} objList.Add(100.00m - GetSum(objList)); return objList;
}
public Decimal GetSum( List<Decimal> objList)
{
Decimal decReturnValue = 0.00m;
if (objList != null)
{
foreach (Decimal decItem in objList)
{
decReturnValue += decItem;
}
}
return decReturnValue;
} public Decimal GetValue(Decimal decValue)
{
if (decValue == 0)
decValue = 100.00m;
Decimal decTemp = 0.0m;
while ((decTemp = 100m*Convert.ToDecimal(new Random().NextDouble())) > decValue && decTemp != 0.00m) { }
return decTemp;
}}
//0+65.828671569856200+34.171328430143800=100
//0+17.268492010081400+17.268492010081400+17.268492010081400+17.268492010081400+17.268492010081400+13.657539949593000=100
//0+41.254063575181200+41.254063575181200+17.491872849637600=100
如果想精确几位小数,需要Decimal.Round(Decimal,intDecimals)