使用Math.pow()函数时出现问题

时间:2013-01-22 12:00:25

标签: java android math

            String loanamount = edtamount.getText().toString();
            double doubleloanamount = Double.parseDouble(loanamount);
            String strloanamount = Double.toString(doubleloanamount);

            Log.v("doubleloanamout", strloanamount);

            String years = edtyears.getText().toString();

            double doubleyears = Double.parseDouble(years) * 12;

            String strpaymentdoubleyears =   Double.toString(doubleyears);
            Log.v("doubleyears", strpaymentdoubleyears);

            double inrate = doubleloanamount * 11 / 100;
            double monthlyrate = inrate / 12;
            double roundmonthlyrate = Math.round(monthlyrate);
            String inratefordemo = Double.toString(roundmonthlyrate);


            double Payment = (doubleloanamount
                    * Math.pow(( roundmonthlyrate) + 1, (doubleyears)) *  roundmonthlyrate)
                    / (Math.pow( roundmonthlyrate + 1, (doubleyears)) - 1);



            double roundpayment = Math.round(Payment);
            String strpayment = Double.toString(roundpayment);
            Log.v("payment", strpayment);
            edtemimonth.setText(strpayment);

我使用上面的代码来计算EMI,但它显示0值。我使用了int和double仍然它给了我0为int 0.0为double

2 个答案:

答案 0 :(得分:6)

因为你是整数的类型转换结果,可能是它有0.55的分数部分,并且由于类型转换它已经删除了分数部分并且仅给出0.尝试将Payment变量更改为double,同时确保{{1} }不等于0。

答案 1 :(得分:0)

使intRate浮动....而计算支付intRate * X如果intRate本身为0则给出0。您已写入intRate = x * 11/100,如果小于1则为0。

还要使mnthRate浮动