i have a method printing times such as: 1.23455 1.26789 1.27853
i want it to be shortened to only two decimal places such as : 1.23 1.26 1.27
System.out.println("time: "+ time);
i have a method printing times such as: 1.23455 1.26789 1.27853
i want it to be shortened to only two decimal places such as : 1.23 1.26 1.27
System.out.println("time: "+ time);
Many, many, many ways... For example you can use String#format(String format, Object... arg)
System.out.println(String.format("time: %.2f", time));
Or using printf
, or DecimalFormat
. I let you googlize it ;)