0
Java random digit to round up the seond decimal place
I using java Math.random to generate any double digit For example: 13.56 how to make this>>>>13.60 13.54 how to make this>>>>15.50 How to make sure i round up to second decimal place to be zero
1 Réponse
+ 1
- start with a double of any precision
- multiply by 10
- use Math.round()
- divide by 10.0
Result is a double with one decimal digit.
Make sure to divide by 10.0 (double) and not by 10 (int) because Math.round will return a long type, and you want to do floating point division rather than integer division.