MCPcopy
hub / github.com/google/gson / stringToNumber

Method stringToNumber

src/main/java/com/google/gson/JsonPrimitive.java:152–167  ·  view source on GitHub ↗
(String value)

Source from the content-addressed store, hash-verified

150 }
151
152 static Number stringToNumber(String value) {
153 try {
154 long longValue = Long.parseLong(value);
155 if (longValue >= Integer.MIN_VALUE && longValue <= Integer.MAX_VALUE) {
156 return (int) longValue;
157 }
158 return longValue;
159 } catch (NumberFormatException ignored) {
160 }
161
162 try {
163 return new BigDecimal(value);
164 } catch (NumberFormatException ignored) {
165 return Double.parseDouble(value); // probably NaN, -Infinity or Infinity
166 }
167 }
168
169 /**
170 * Check whether this primitive contains a String value.

Callers 2

getAsNumberMethod · 0.95
parseRecursiveMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected