File: interpolationMultiline1.scala

package info (click to toggle)
scala 2.11.12-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 62,828 kB
  • sloc: javascript: 28,808; java: 13,415; xml: 3,250; sh: 1,620; python: 756; makefile: 38; awk: 36; ansic: 6
file content (26 lines) | stat: -rw-r--r-- 579 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
object Test extends App {

  def test1(n: Int) = {
    println(s"""Bob is $n years old""")
    println(f"""Bob is $n%2d years old""")
    println(s"""Bob will be ${n+1} years old""")
    println(f"""Bob will be ${n+1}%2d years old""")
    println(s"""$n+1 = ${n+1}""")
    println(f"""$n%d+1 = ${n+1}%d""")
  }

  def test2(f: Float) = {
    println(s"""Best price: $f""")
    println(f"""Best price: $f%.2f""")
    println(s"""$f% discount included""")
    println(f"""$f%3.2f%% discount included""")
  }

  test1(1)
  test1(12)
  test1(123)

  test2(10.0f)
  test2(13.345f)

}