简体   繁体   中英

Android: How to use mathematical expression in android

I am new to android. And i am making mortgage application. I want to find the monthly interest with following equation.

M= (P *(J/1-(1+J)^-n)) + T

I have received all the values of different fields .But i don't understand how to implement with this equation.

Please suggest me or guide me the way to do so.

Thanks

You can use the Math.pow method

sample:

double P;
double J;
double M;
double T;
double n;
M= (P * (J/1- Math.pow((1+J), -n))) + T;

In Java, most of the basic math operators are what you would expect. ( + , - , * , / ). The tricky one is exponentiation. Use the Math library and the pow function, writing something like Math.pow(a, b) to compute a^b .

For more information, check the Java documentation. For example, Math.pow is at: http://docs.oracle.com/javase/6/docs/api/java/lang/Math.html#pow(double,%20double)

You'll want to use the Math library Java provides in Java.lang.Math

Documentation from google can be found here

import Java.lang.Math

//a simple exponentiation example

double base = 2.0;
double exponent = 3.0;

double exponentiation_result = Math.pow(base, exponent)

Note that the method Math.pow requires that you use the double class, which stores numbers with decimal-point precision. Other operations, such as division and subtraction, can be done with mathematical symbols

int y = a * (b - c)

Your example, left as an exercise, will require use of parentheses to maintain order of operation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM