java - How to get user friendly values of Cos and Tan functions? -


i working on android calculator application can calculate trigonometric functions. find calculator shows:

cos 90° = 6.123233995736766e-17 instead of  cos 90° = 0 cos 270° = -1.8369701987210297e-16 instead of cos 270° = 0  tan 180° = -1.2246467991473532e-16 instead of tan 180° = 0 tan 360° = -2.4492935982947064e-16 instead of tan 360° = 0 

i know these values mean 0 these calulations might little confusing users. have tested cos , tan values of 0°, 15°, 18°, 22.5°, 30°, 36°, 45°, 60° , 72°. seem work fine. using eclipse make app.

my question "how calculator show user friendly values of cos , tan functions?".

this code cos , tan function:

imagebutton btncos; imagebutton btntan; textview txtdisplay;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      btncos = (imagebutton) findviewbyid(r.id.btncos);     btntan = (imagebutton) findviewbyid(r.id.btntan);     txtdisplay = (textview) findviewbyid(r.id.txtdisplay);      btncos.setonclicklistener(this);     btntan.setonclicklistener(this);  }  double total = 0.0;  @override public void onclick(view v) {     // todo auto-generated method stub  if (v.getid() == r.id.btncos) {     if (txtdisplay.gettext().equals("")) {         txtdisplay.settext("");     }     else {         total = math.cos(math.toradians(double.parsedouble(txtdisplay.gettext().tostring())));         txtdisplay.settext("");         txtdisplay.settext(txtdisplay.gettext().tostring() + total);     } } else if (v.getid() == r.id.btntan) {     if (txtdisplay.gettext().equals("")) {         txtdisplay.settext("");     }     else {         total = math.tan(math.toradians(double.parsedouble(txtdisplay.gettext().tostring())));         txtdisplay.settext("");         txtdisplay.settext(txtdisplay.gettext().tostring() + total);     } } 

java math trig functions use radians. there utility function, math.toradians(degrees) (and need round() - believe want this,

system.out.println(math.round(math.cos(math.toradians(90)))); 

output is

0 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -