官术网_书友最值得收藏!

f Interpolator

To have something like printf styled formatting in Scala, we can use the f interpolator. We do this by using a f preceding the double quotes of our string, and then within the String we can use one of the format specifiers:

scala> val amount = 100
amount: Int = 100
scala> val firstOrderAmount = f"Your total amount is: $amount%.2f"
firstOrderAmount: String = Your total amount is: 100.00

From the preceding example, it's clear that we use f as a prefix to our string and use $ followed by the expression that includes our format specifier. This works as a formatter for our strings.

A few format specifiers are listed as following:

Format Specifiers
主站蜘蛛池模板: 武平县| 金堂县| 苍山县| 克什克腾旗| 广宁县| 宁晋县| 诸城市| 扶绥县| 磐石市| 丹江口市| 腾冲县| 民和| 青冈县| 金华市| 兖州市| 英德市| 兴义市| 子洲县| 泊头市| 呼玛县| 新民市| 怀仁县| 读书| 甘洛县| 天门市| 江达县| 新兴县| 鸡东县| 新疆| 皋兰县| 正安县| 东山县| 宜川县| 鄱阳县| 巍山| 确山县| 哈巴河县| 绿春县| 翼城县| 巩义市| 德安县|