I'm trying to learn how to do math on an android environment. Basicly what I am trying to do is convert a set of numbers into Years, Months and days. This is what I have so far:
The only problem is that the output is the years with a long set of decimals. So if I enter 1000 in the in the field I get "2.739726027397260273972602739726" years. In order for me to get the months I need to limit the decimals to so that all I am left is "2". I been looking around but I can't seem get it to work. Any thoughts?
Any advice or recommendations will greatly be appreciated.
Code:
protected void convertNumbersToTotalTime() {
double val = Double.parseDouble(numbers.getText().toString());
double val2 = (val / 365);
double val3 = (val2 * 365);
double val4 = (val - val3);
double val5 = (val4 / 30);
double val6 = (val5 * 30);
double val7 = (val4 - val6);
String val8 = val2 + " Years " + val5 + " Months " + val7 + " days";
outputnum.setText(val8);
}
The only problem is that the output is the years with a long set of decimals. So if I enter 1000 in the in the field I get "2.739726027397260273972602739726" years. In order for me to get the months I need to limit the decimals to so that all I am left is "2". I been looking around but I can't seem get it to work. Any thoughts?
Any advice or recommendations will greatly be appreciated.