@@ -148,14 +148,16 @@ protected Number extractFloat() throws ParseException {
148
148
149
149
// follow JSonIJ parsing method
150
150
if (xs .length () > 18 ) {
151
- BigDecimal big = new BigDecimal (xs );
152
151
// use extra CPU to check if the result can be return as double without precision lost
153
152
if (!unrestictBigDigit ) {
154
153
double asDouble = Double .parseDouble (xs );
155
- if (String .valueOf (asDouble ).equals (xs ))
154
+ final String doubleStr = String .valueOf (asDouble );
155
+ // we need a compare compat `e` `E` `e+` `E+`
156
+ if (compareDoublePrecision (doubleStr , xs )){
156
157
return asDouble ;
158
+ }
157
159
}
158
- return big ;
160
+ return new BigDecimal ( xs ) ;
159
161
}
160
162
161
163
return Double .parseDouble (xs );
@@ -165,6 +167,33 @@ protected Number extractFloat() throws ParseException {
165
167
}
166
168
}
167
169
170
+ private boolean compareDoublePrecision (String convert , String origin ) {
171
+ final char [] charArray = convert .toCharArray ();
172
+ final char [] originArray = origin .toCharArray ();
173
+ if (charArray .length > originArray .length ) {
174
+ return false ;
175
+ }
176
+ int j = 0 ;
177
+ for (int i = 0 ; i < charArray .length ; i ++) {
178
+ if (charArray [i ] < '0' || charArray [i ] > '9' ) {
179
+ if (originArray [j ] >= '0' && originArray [j ] <= '9' ) {
180
+ return false ;
181
+ } else {
182
+ j ++;
183
+ if (originArray [j ] == '+' ) {
184
+ j ++;
185
+ }
186
+ continue ;
187
+ }
188
+ }
189
+ if (charArray [i ] != originArray [j ]) {
190
+ return false ;
191
+ }
192
+ j ++;
193
+ }
194
+ return j == originArray .length ;
195
+ }
196
+
168
197
/**
169
198
* use to return Primitive Type, or String, Or JsonObject or JsonArray
170
199
* generated by a ContainerFactory
0 commit comments