MCPcopy
hub / github.com/ccxt/ccxt / toDouble

Method toDouble

java/lib/src/main/java/io/github/ccxt/Helpers.java:891–905  ·  view source on GitHub ↗
(Object o)

Source from the content-addressed store, hash-verified

889 }
890
891 private static double toDouble(Object o) {
892 if (o instanceof Double) return (Double) o;
893 if (o instanceof Float) return ((Float) o).doubleValue();
894 if (o instanceof Long) return ((Long) o).doubleValue();
895 if (o instanceof Integer) return ((Integer) o).doubleValue();
896 if (o instanceof BigDecimal) return ((BigDecimal) o).doubleValue();
897 if (o instanceof String) {
898 try { return Double.parseDouble((String) o); } catch (NumberFormatException ex) { return 0.0; }
899 }
900 // Mirror TS's silent-NaN-or-default semantics: returning 0.0 instead of
901 // throwing keeps a single misuse (e.g. passing a Map to `sum`) from
902 // killing the whole WS connection. See Generic.toDouble for the same
903 // rationale and test coverage.
904 try { return Double.parseDouble(String.valueOf(o)); } catch (NumberFormatException ex) { return 0.0; }
905 }
906
907 private static float toFloat(Object o) {
908 if (o instanceof Float) return (Float) o;

Callers 11

isEqualMethod · 0.95
isGreaterThanMethod · 0.95
modMethod · 0.95
addMethod · 0.95
subtractMethod · 0.95
divideMethod · 0.95
multiplyMethod · 0.95
mathMinMethod · 0.95
mathMaxMethod · 0.95
parseFloatMethod · 0.95
toFixedMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected