爲了格式化Long或Double類型變量,'%'後面應該用什麼後綴?在Scala中格式化長和雙println
var LONG : Long = 9L;
println("The value of LONG is %?".format(LONG));
var DOUBLE : Double = 9.9;
println("The value of DOUBLE is %?".format(DOUBLE));
非常感謝。
爲了格式化Long或Double類型變量,'%'後面應該用什麼後綴?在Scala中格式化長和雙println
var LONG : Long = 9L;
println("The value of LONG is %?".format(LONG));
var DOUBLE : Double = 9.9;
println("The value of DOUBLE is %?".format(DOUBLE));
非常感謝。
這裏是你如何在println
發言中,我們可以使用的String.format()方法的格式,格式如下圖所示
var LONG : Long = 9L;
println("The value of LONG is %d\n".format(LONG))
var DOUBLE : Double = 9.9;
printf("The value of DOUBLE is %.2f".format(DOUBLE));
結果你: -
LONG的值是9
DOUBLE的值是9.90
val height = 1.9d
val weight = 100L
val name = "James"
println(f"$name%s is $height%2.2f meters tall and weights $weight%3d kg") // James is 1.90 meters and weights 100 kg
http://docs.scala-lang.org/overviews/core/string-interpolation.html – volia17
http://docs.oracle.com/javase/7/docs/api /java/util/Formatter.html – gzm0