Skip to content

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

@davydog187

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

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