in this app a random number between 0-5 appears when the button is clicked. The Problem is, that the number appears as a pointnumber instead of a "normal" number. For example: 4.7920870175158825
The second Problem is, that sometimes a number with a 0 before the comma appears, For example: 0.7518324225208361
How can I fix this?
Thank´s in advance. :)
MainActivity.java:
public class MainActivity extends ActionBarActivity {
Button btn;
TextView tw;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.btn);
tw = (TextView) findViewById(R.id.tw);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tw.setText("Random Number: " + Math.random()*5);
}
});
}
}
0 comments:
Post a Comment