Fix format float numbers #12

Closed
Enyby wants to merge 5 commits from patch-5 into master
Showing only changes of commit 0b2f11ca5c - Show all commits

View File

@@ -343,6 +343,8 @@ public class StringLib extends TwoArgFunction {
public final int conversion;
public final int length;
public final String src;
public FormatDesc(Varargs args, LuaString strfrmt, final int start) {
int p = start, n = strfrmt.length();
int c = 0;
@@ -390,6 +392,8 @@ public class StringLib extends TwoArgFunction {
zeroPad &= !leftAdjust; // '-' overrides '0'
conversion = c;
length = p - start;
String str = strfrmt.tojstring();
src = str.substring(start - 1, p);
}
public void format(Buffer buf, byte c) {
@@ -465,8 +469,13 @@ public class StringLib extends TwoArgFunction {
}
public void format(Buffer buf, double x) {
// TODO
buf.append( String.valueOf( x ) );
String out;
try {
String.format(src, x);
} catch (Throwable e) {
out = String.valueOf( x );
}
buf.append( out );
}
public void format(Buffer buf, LuaString s) {