System.out.printf¶
In [1]:
System.out.printf("Pi: %.2f", 3.1415926)
Out[1]:
String.format¶
In [2]:
String.format("%1.2f", 3.1415926)
Out[2]:
In [3]:
"%1.2f".format(3.1415926)
Out[3]:
java.text.DecimalFormat¶
In [4]:
import java.text.DecimalFormat
DecimalFormat("#.##").format(3.1415926)
Out[4]:
kotlin.math.round¶
In [6]:
kotlin.math.round(3.1415926)
Out[6]:
In [7]:
kotlin.math.round(3.1415926 * 100) / 100.0
Out[7]:
In [9]:
%classpath add mvn org.apache.commons commons-math3 3.6.1
In [10]:
import org.apache.commons.math3.util.Precision
Precision.round(3.1415926, 2)
Out[10]:
In [ ]: