Skip to content

Commit 4c2603b

Browse files
committed
javajs.util.DF (decimal formatter) and PT (parser)
1 parent 7f7e94b commit 4c2603b

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

sources/net.sf.j2s.java.core/src/javajs/util/DF.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public static String formatDecimal(float value, int decimalDigits) {
118118
n = PT.parseInt(s1.substring(pt1 + 1));
119119
// 3.567E-2
120120
// 0.03567
121+
// -0.0001
121122
s1 = "0." + zeros.substring(0, -n - 1) + s1.substring(0, 1) + s1.substring(2, pt1);
122123
pt = 1;
123124
}
@@ -142,8 +143,11 @@ public static String formatDecimal(float value, int decimalDigits) {
142143
value + (isNeg ? -1 : 1) * formatAdds[decimalDigits], decimalDigits);
143144
}
144145

145-
SB sb = SB.newS(s1.substring(0, (decimalDigits == 0 ? pt
146-
: ++pt)));
146+
String s0 = s1.substring(0, (decimalDigits == 0 ? pt
147+
: ++pt));
148+
SB sb = SB.newS(s0);
149+
if (isNeg && s0.equals("0.") && decimalDigits + 2 <= len && s1.substring(2, 2 + decimalDigits).equals(zeros.substring(0, decimalDigits)))
150+
isNeg = false;
147151
for (int i = 0; i < decimalDigits; i++, pt++) {
148152
if (pt < len)
149153
sb.appendC(s1.charAt(pt));

sources/net.sf.j2s.java.core/src/javajs/util/PT.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -816,13 +816,12 @@ public static String toJSON(String infoType, Object info) {
816816
while (true) {
817817
if (info instanceof String) {
818818
s = (String) info;
819-
/**
820-
* @j2sNative
821-
*
822-
* if (typeof s == "undefined") s = "null"
823-
*
824-
*/
825-
{}
819+
// /**
820+
// * @j2sNative
821+
// *
822+
// * if (typeof s == "undefined") s = "null"
823+
// *
824+
// */
826825

827826
if (s.indexOf("{\"") != 0) {
828827
//don't doubly fix JSON strings when retrieving status

0 commit comments

Comments
 (0)