0

kotlin double 保留两位小数

simona created at5 years ago view count: 8276
import java.text.DecimalFormat

 @JvmStatic object Test {
   fun main(args: Array<String>) {

        val df = DecimalFormat("######0.00")

        val d1 = 3.141592684
        val d2 = 0.0
        val d3 = 2.0
        print(df.format(d1))
        print(df.format(d2))
        print(df.format(d3))

    }
}
/*
输出
3.14
0.00
2.00
*/
report
回复

相关搜索关键词

Recent search keywords