Menu

#53 string.format %f ignores precision

v3.0-beta1
open
nobody
None
5
2018-02-27
2018-02-27
No

string.format('%2f', 1.23456)
returns 1.23456 instead of 1.23
Here's a test case

    @Test public void stringFormat() throws ScriptException {
        ScriptEngineManager mgr = new ScriptEngineManager();
        ScriptEngine e = mgr.getEngineByName("luaj");
        e.eval("y = string.format('%.2f', 1.23456)");
        Assert.assertEquals("1.23", (String) e.get("y"));
    }

Discussion


Log in to post a comment.