【发布时间】:2017-01-24 07:51:32
【问题描述】:
我正在尝试将金额从数字转换为字符串。在将3070 转换为three thousand seventy only 时,我注意到代码中有一个缺陷,输出应该是three thousand seventy only,但输出是Three Thousand Rupees only。
我从网上得到了代码,
当我调试代码时,我看到以下几行
if ((rupees / 1000) > 0)
{
res = rupees / 1000;
rupees = rupees % 1000;
result = result + ' ' + rupeestowords(res) + " Thousand";
}
这个代码出现问题是因为1010,1020,.....,3070,3080,3090,4010,4020.etc所有的数字都是%到1000,这意味着如果我输入这些数字,输出就会出错,
我无法在这里得到正确的逻辑。我想我需要在另一个 if 条件下再次验证卢比。
代码低于 X 千
if ((rupees / 100) > 0)
{
res = rupees / 100;
rupees = rupees % 100;
result = result + ' ' + rupeestowords(res) + " Hundred";
}
if ((rupees % 10) > 0)
{
res = rupees % 100;
result = result + " " + rupeestowords(res);
}
result = result + ' ' + " Rupees only";
return result;
}
【问题讨论】:
-
我认为您还需要添加以下转换。 rupeestowords(卢比)
-
你能帮我解决这个问题吗?你能告诉我答案吗
-
这不可能是整个代码...错误必须在brachen中 if((rupees / 100) > 0) 或更可能在 if ((rupees /10) > 0)
-
您已经发布了运行正常的 x 千位代码。发布执行十(七十)位的代码,或者实际上只是发布所有代码。
标签: c# numbers string-formatting