0Pricing
Lua Academy · Lesson

Number Formatting

Display numbers nicely.

Why Format Numbers?

Raw numbers do not always print the way you want. A price might show as 2.5 when you want 2.50, or a long float fills the screen with digits.

Number formatting lets you control exactly how numbers appear in text.

print(2.5)
print(1 / 3)

Meet string.format

The main tool for formatting is string.format(). You give it a template with placeholders and the values to fill in.

A placeholder starts with %, like %d for an integer or %f for a float.

print(string.format("Score: %d", 42))

All lessons in this course

  1. Integers and Floats
  2. Arithmetic Operators
  3. The math Library
  4. Number Formatting
← Back to Lua Academy