2015-06-24 60 views
1

爲了格式化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)); 

非常感謝。

+1

http://docs.scala-lang.org/overviews/core/string-interpolation.html – volia17

+0

http://docs.oracle.com/javase/7/docs/api /java/util/Formatter.html – gzm0

回答

0

In Scala we write

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