Rounding the Decimal to 1.00 and 0.10 in Android -


as title, how round decimal 1.00 if number 1.01,1.02,1.03,1.04 , round decimal 0.10 if number 0.05,0.06,0.07,0.08,0.09

you can try below code:

 private static void roundoff(double num) {     double intpart = (int) num;     double rondededoffnum = intpart+ math.round((num- intpart)*10)/10.0;     system.out.println(rondededoffnum); } 

Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -