C# 金额转换问题,从数字到字符

C# 金额转换问题,从数字到字符,c#,numbers,string-formatting,C#,Numbers,String Formatting,我正在尝试将一个金额从数字转换为字符串。在将3070转换为3700卢比时我注意到代码中有一个缺陷,输出应该是3700卢比,但不是这个,而是3000卢比 我从网上得到了密码 当我调试代码时,我看到以下几行 if ((rupees / 1000) > 0) { res = rupees / 1000; rupees = rupees % 1000; result = result + ' ' + rupee

我正在尝试将一个金额从数字转换为字符串。在将
3070
转换为
3700卢比时
我注意到代码中有一个缺陷,输出应该是
3700卢比
,但不是这个,而是
3000卢比

我从网上得到了密码

当我调试代码时,我看到以下几行

if ((rupees / 1000) > 0)
        {
            res = rupees / 1000;
            rupees = rupees % 1000;
            result = result + ' ' + rupeestowords(res) + " Thousand";
        }
此代码中出现问题是因为所有数字都是%到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;
    }
在此代码中:

if ((rupees % 10) > 0)
{
    res = rupees % 100;
    result = result + " " + rupeestowords(res);
}
这一行是错误的:

res = rupees % 100;   
if ((rupees % 10) > 0)
应该是

res = rupees / 10;
此外,以下行是错误的:

res = rupees % 100;   
if ((rupees % 10) > 0)
应该是:

if ((rupees / 10) > 0)
离开:

if ((rupees / 10) > 0)
{
    res = rupees % 10;
    result = result + " " + rupeestowords(res);
}

我认为您还需要添加以下转换。你能帮我解决这个问题吗??你能告诉我答案吗?这个可能的副本不可能是整个代码。。。如果((卢比/100)>0,则错误必须出现在brachen中,如果((卢比/10)>0,则更可能出现在)您发布了执行x千位的代码,该代码工作正常。发布完成十(七十)位的代码,或者实际上只是发布所有代码。仍然不进入循环编辑我的答案,还有一行不正确-你选择了一些糟糕的代码来使用现在我只有在输入值为3050的情况下才能得到3500卢比再次更改答案-你可以自己这样做当然应该是:res=卢比/10;