如何在 Scala 中格式化字符串? [英] How to format strings in Scala?
本文介绍了如何在 Scala 中格式化字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要打印一个包含 scala.Long 的格式化字符串.java.lang.String.format() 与 scala.Long(编译时)和 RichLong(java.util.IllegalFormatConversionException)不兼容
I need to print a formatted string containing scala.Long. java.lang.String.format() is incompatible with scala.Long (compile time) and RichLong (java.util.IllegalFormatConversionException)
编译器在以下工作代码中警告弃用整数:
Compiler warns about deprecation of Integer on the following working code:
val number:Long = 3243
String.format("%d", new java.lang.Long(number))
我是否应该更改格式化程序、数据类型或其他内容?
Should I change fomatter, data type or something else?
推荐答案
您可以尝试以下操作:
val number: Long = 3243
"%d".format(number)
这篇关于如何在 Scala 中格式化字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文