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

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
主站蜘蛛池模板: 南丰县| 水富县| 吉木乃县| 洛扎县| 甘泉县| 大方县| 龙陵县| 三穗县| 射洪县| 乐至县| 嘉鱼县| 射阳县| 板桥市| 兴文县| 搜索| 呈贡县| 伊金霍洛旗| 鹰潭市| 修文县| 瓦房店市| 永靖县| 绍兴县| 海城市| 丹寨县| 乐亭县| 方城县| 中卫市| 邯郸市| 张家川| 曲沃县| 故城县| 晋城| 三河市| 房山区| 曲麻莱县| 治多县| 彭州市| 霸州市| 英吉沙县| 浦县| 上虞市|