Skip to content

string.format does not support precision specifiers (%.2f, %05d, etc.) #148

Closed

Description

@davydog187

Severity: Medium
Area: Standard library — lib/lua/vm/stdlib/string.ex

Description

string.format raises "bad argument to 'string.format' (invalid option '%.')" when given format specifiers with precision (e.g., %.2f) or width-and-precision combinations. Standard Lua 5.3/5.4 supports the full C printf-style format string syntax.

Reproduction

return string.format("%.2f", 3.14159)
-- Expected: "3.14"
-- Actual: ** (Lua.RuntimeException) bad argument to 'string.format' (invalid option '%.')

Workaround

Use %f (full float) or convert manually with math.floor / string concatenation.


Summary Table

# Bug Severity Status
1 local function declarations silently dropped High Open
2 function Table.method() dot-syntax fails at runtime High Open
3 Multiple for loops with the same variable name corrupt register allocation High Open
4 Register overlap in nested functions causes infinite for loops Critical Fixed
5 string.format does not support precision specifiers Medium Open

Activity

  1. davydog187 commented on May 4, 2026

    @davydog187
    ContributorAuthor

    This was fixed in PR #136 (Phase 16 — string.format width/precision).

    Verified on main (835de36):

    return string.format("%.2f", 3.14159)  -- returns "3.14" ✓

    Closing as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions