java - find out the log value of a number from input -
i have edittext field users input. user can enter values ten digit number.when clicking on button, need show log [ mathematics log ] value of number in double precision.
that showned below.
if input xxxxxxxxxx [ consider number ]
the output must yy.yy.
package com.example.logvalue; import android.os.bundle; import android.app.activity; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.edittext; import android.widget.toast; public class main extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); edittext edit = (edittext) findviewbyid(r.id.edittext1); final int noo = integer.parseint(edit.gettext().tostring()); button b1 = (button) findviewbyid(r.id.button1); b1.setonclicklistener(new onclicklistener() { public void onclick(view arg0) { toast.maketext(main.this, string.format("%.2f", math.log10(noo)) , toast.length_long).show(); } }); } }
use string.format("%.2f", math.log10(number))
syntax. string class has format function these.
i assume want logarithm base of 10.
explanation: string.format
java-equavalient of traditional printf
c++. %
symbol means there fetched argument list, point means want specify number of decimals, , hence put 2 after point. hope helped.
Comments
Post a Comment