感谢劳伦斯伯克在isMaybeMoney函数的其他问题,我能够确定输入是否是金钱。计算利息无限?
我现在在做的是试图计算兴趣后的总数,但我一直让Infinity写入屏幕。我感兴趣的功能是什么在世界上是错误的?如果我用1,234美元作为3.5%利息的起始余额,应该是3,522.55美元。
有人可以帮我吗?
static float money;
static void Main()
{
string[] myMaybeBalances = Accounts.GetStartingBalances();
myIsMaybeMoneyValidator Miimv = new myIsMaybeMoneyValidator();
ArrayList interests = Miimv.interestsAccrued(myMaybeBalances);
foreach (object interest in interests)
{
Console.WriteLine(interest);
}
Console.ReadLine();
}
public ArrayList interestsAccrued(string[] myMaybeBalances)
{
ArrayList interests = new ArrayList();
foreach (string myMaybeBalance in myMaybeBalances)
{
bool myResult = isMaybeMoney(myMaybeBalance);
if (myResult == true)
{
decimal[] rates = Accounts.GetRates();
for (int i = 0; i < rates.Length; i++)
{
decimal rate = rates[i];
float total = 1;
int n_X_t = 360;
while (n_X_t != 0)
{
rate = (1 + rates[i]/12);
float myRate;
float.TryParse(rate.ToString(), out myRate);
total = total * myRate;
total = total * money;
n_X_t = n_X_t - 1;
}
interests.Add(total);
}
}
}
return interests;
}
public bool isMaybeMoney(object theirMaybeMoney)
{
string myMaybeMoney = theirMaybeMoney.ToString();
float num;
bool isValid = float.TryParse(myMaybeMoney,
NumberStyles.Currency,
CultureInfo.GetCultureInfo("en-US"), // cached
out num);
money = num;
return isValid;
}
你为什么在所有的时间之间浮动和小数之间转换?浮点数字计算不适合 - 摆脱它。 (为什么你不使用.NET命名约定或泛型?) – 2012-03-07 23:59:36
这是干什么的:'total = total * money;'? – 2012-03-08 00:00:52
'rates [0]'的值是多少? – 2012-03-08 01:28:22