double value = Math.tan(Math.toRadians(Double.parseDouble(txtCalc.getText().toString())));
value = ((double) Math.round(value * 1000)) / 1000;
setValue(Double.toString(value));
Display value from Math.tan() in degrees?
Question
I'm learning programming for android and i made a calculator. The calculator is working fine but I'm having troubles with my sin, cos and tan formulas. I would like to display the values in degrees instead of radians.
Here is the piece of code that applies to that.
btnTan.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
setValue(Double.toString(Math.tan(Double.parseDouble(txtCalc
.getText().toString()))));
}
});
And this is the function setValue
private void setValue(String value) {
if (operator == 0)
reset();
if (readyToClear) {
readyToClear = false;
}
txtCalc.setText(value);
txtCalc.setSelection(value.length());
hasChanged = true;
}
I would like to have another buttons that would toggle between radians and degrees like the Iphone calculator.
Thank you!
La solution
Autres conseils
and
so you can adjust you variables accordingly
1 radian = 57.2957795 degrees
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow