After this lesson
- Convert a numeric result to text.
- Control leading zeros and rounding.
- Distinguish frame counters, timecode and real clocks.
Before you start
- Composition
- A separate Fusion Composition. 1920×1080, square pixels, 25 fps.
- Parameter
- Text1 → Styled Text
- Range
- Start at comp.RenderStart. Reference frames are local unless stated otherwise.
A text expression must return text. It can display numbers, percentages and timers while keeping Text+ styling. Recalculating content is different from character animation.
Turning a number into text
Text(string.format("%03d", 12)) returns 012. %d means integer; 03 means a minimum width padded with zeros. Use a format such as %.1f for decimals. Define rounding before integer formatting.
math.floor rounds down. For a non-negative value, round to nearest using math.floor(value+0.5). Check the behavior before applying this to negative numbers.
Frame and second counters
The formula below displays the local frame number. For elapsed whole seconds at 25 fps, divide the time offset by 25 before applying floor.
Text(string.format("%03d", math.floor(math.max(0, time - comp.RenderStart))))Strings and Cyrillic text
Lua concatenates with .., for example "Frame " .. string.format("%03d", 12). Do not use JavaScript backtick templates.
Basic Lua string operations work on bytes. Cutting a Cyrillic string one byte at a time with string.sub can corrupt UTF-8. Use Write On or Follower for character reveals instead of manual byte slicing.
Styling and purpose
Unequal digit widths can make a timer jump visually. Choose a font with suitable digits and check alignment. A text counter of seconds is not automatically SMPTE timecode or the camera’s source timecode.
What %03d means
In string.format, %03d requests an integer at least three characters wide, padded with leading zeros. 9 gives 009, 100 gives 100 and 1000 gives 1000: the width is a minimum, not a maximum. Apply floor first to make integer rounding explicit.
The outer Text constructs the Styled Text result. Remove formatting to check the number itself, then restore leading zeros. Keep units next to labels: frame for a local frame number, s for seconds. Frame 100 in a 25 fps project does not mean 100 seconds.
Why digits jump even with a correct formula
Different glyph widths for 1 and 8 can create horizontal jitter. Leading zeros preserve the character count, but not the total width in a proportional font. Choose tabular digits or a suitable monospaced font and lock the alignment.
For a percentage counter, define the range, such as 0…100, before choosing rounding. Ordinary rounding can display 100% before the actual end; floor holds 99 until progress reaches one. This is a design decision: keep it consistent with a progress bar showing the same value.
Parameters and ranges
| Parameter | What it changes | Example / check |
|---|---|---|
| Text(…) | A text result for Styled Text. | Not used for numeric Size. |
| string.format("%03d", n) | An integer with at least three digits. | 9 → 009; 1000 is not truncated. |
| math.floor(…) | Rounds down. | For timers, apply it after converting frames to seconds. |
| time−comp.RenderStart | Local counter. | Starts at zero regardless of the absolute start. |
USE IN A COMPOSITION
Build it in Fusion
Text1 → Styled Text
Solid lines are node connections in the Flow. A dashed line is a parameter dependency configured in the Inspector.
Connections by port and parameter2
Color is determined by the destination input. Dashed connections are configured in the Inspector; they do not add an RGBA wire to the Flow.
Assembly steps
- Create Text+.
- Enable Expression on Styled Text.
- Paste the frame-counter formula.
- Check the start, frame 9 and frame 100; adjust alignment.
Text(string.format("%03d", math.floor(math.max(0, time - comp.RenderStart))))Expected result. The counter shows 000, 009 and 100. Values beyond 999 are not truncated because the format specifies a minimum width.
Checkpoints
| When / what to check | Expected | Why check it |
|---|---|---|
| Local 0 | 000 | Initial format. |
| 9 | 009 | Leading zeros. |
| 100 | 100 | The third digit is occupied. |
| 1000 | 1000 | No maximum width restriction. |
INTERACTIVE EXAMPLE
Change a parameter. Compare the result.
The frame number becomes text
Text1 → Styled TextThe local frame is rounded down and written with at least three digits. Zeros pad a short number without truncating a longer one.
Frames 0, 9, 100 and 1000 produce 000, 009, 100 and 1000. This counts frames, not seconds.
Formula for the current settings +
Text(string.format("%03d", math.floor(math.max(0, time - comp.RenderStart))))The browser reproduces the numeric core and formatting result. Text and string.format run in Fusion after you paste the formula.
Errors and troubleshooting
Cyrillic letters turn into corrupted characters
Do not slice UTF-8 byte by byte. Use the built-in character-animation tools.
The counter shows fractions
Round explicitly and choose an integer format.
Independent exercise
Display elapsed seconds with one decimal place at 25 fps.
Show the solution and explanation
Text(string.format("%.1f", math.max(0,time-comp.RenderStart)/25)). Numeric literals inside the formula still use a decimal point.
Continue learning
Official sources
An original educational walkthrough. The browser model explains the principle but does not run Fusion. Control placement depends on the version; save the original composition before replacing a parameter's control source.