gpt4 book ai didi

scala - 在 Scala println 中格式化 Long 和 Double

转载 作者:行者123 更新时间:2023-12-04 00:40:58 24 4
gpt4 key购买 nike

为了格式化 Long 或 Double 类型变量,我应该使用 '%' 之后的后缀是什么?

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));

非常感谢。

最佳答案

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

关于scala - 在 Scala println 中格式化 Long 和 Double,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31034029/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com