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

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
主站蜘蛛池模板: 昌江| 彭州市| 沿河| 绥滨县| 洞口县| 灵山县| 乐平市| 育儿| 昌都县| 小金县| 梨树县| 镇原县| 清丰县| 那坡县| 黑河市| 西充县| 大余县| 勐海县| 杭州市| 来宾市| 荔波县| 科尔| 南汇区| 纳雍县| 维西| 海兴县| 泊头市| 黄山市| 平安县| 康平县| 庐江县| 江西省| 临江市| 台南市| 绿春县| 宁化县| 南涧| 甘谷县| 织金县| 湛江市| 当阳市|