string_formatting.gd 668 B

123456789101112131415161718
  1. func test():
  2. print("hello %s" % "world" == "hello world")
  3. print("hello %s" % true == "hello true")
  4. print("hello %s" % false == "hello false")
  5. print("hello %d" % 25 == "hello 25")
  6. print("hello %d %d" % [25, 42] == "hello 25 42")
  7. # Pad with spaces.
  8. print("hello %3d" % 25 == "hello 25")
  9. # Pad with zeroes.
  10. print("hello %03d" % 25 == "hello 025")
  11. print("hello %.02f" % 0.123456 == "hello 0.12")
  12. # Dynamic padding:
  13. # https://docs.godotengine.org/en/latest/getting_started/scripting/gdscript/gdscript_format_string.html#dynamic-padding
  14. print("hello %*.*f" % [7, 3, 0.123456] == "hello 0.123")
  15. print("hello %0*.*f" % [7, 3, 0.123456] == "hello 000.123")