- Learning Scala Programming
- Vikash Sharma
- 119字
- 2021-06-30 19:07:53
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
推薦閱讀
- Advanced Splunk
- Redis Applied Design Patterns
- Vue.js前端開發(fā)基礎(chǔ)與項(xiàng)目實(shí)戰(zhàn)
- C語言程序設(shè)計(jì)基礎(chǔ)與實(shí)驗(yàn)指導(dǎo)
- x86匯編語言:從實(shí)模式到保護(hù)模式(第2版)
- Effective Python Penetration Testing
- Modular Programming in Java 9
- Mathematica Data Analysis
- Mastering Drupal 8 Views
- 第一行代碼 C語言(視頻講解版)
- Python期貨量化交易實(shí)戰(zhàn)
- 從零開始構(gòu)建深度前饋神經(jīng)網(wǎng)絡(luò):Python+TensorFlow 2.x
- 菜鳥成長(zhǎng)之路
- ASP.NET Core 2 High Performance(Second Edition)
- 數(shù)據(jù)庫技術(shù)及應(yīng)用教程上機(jī)指導(dǎo)與習(xí)題(第2版)