Kotlin只截取Float小数点后数值DecimalFormat

Kotlin只截取Float小数点后数值DecimalFormat 

 

import java.text.DecimalFormat

fun main(args: Array<String>) {
    val pi = 3.141516F
    var p = pi - pi.toInt()
    println(p)

    val decimalFormat = DecimalFormat("00.0000")
    val format = decimalFormat.format(p)
    println(format)
    println(format.toFloat())
}

0.14151597
00.1415
0.1415

Java小数点数字和百分号数字之间的转换_zhangphil的博客-CSDN博客Java小数点数字和百分号数字之间的转换小数点数字和百分号(百分比)数字之间的转换在证券金融业很常见,需要经常进行两者之间相互转换。如代码: String s1 = "21.8%"; String s2 = "-21.7%"; NumberFormat numberFormat = NumberFormat.getPercentInstance();...https://blog.csdn.net/zhangphil/article/details/80003751

猜你喜欢

转载自blog.csdn.net/zhangphil/article/details/132836956