Kotlin only intercepts the value after the decimal point of FloatDecimalFormat

Kotlin only intercepts the value after the decimal point of FloatDecimalFormat 

 

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

 

 

 

Conversion between Java decimal point numbers and percent sign numbers_zhangphil's blog - CSDN blog Java conversion between decimal point numbers and percent sign numbers Conversion between decimal point numbers and percent sign (percent) numbers is very important in the securities and financial industry It is common and requires frequent conversion between the two. Such as code: String s1 = "21.8%"; String s2 = "-21.7%"; NumberFormat numberFormat = NumberFormat.getPercentInstance();... https://blog.csdn.net/zhangphil/article/details/80003751

 

Guess you like

Origin blog.csdn.net/zhangphil/article/details/132836956