@Test public void testToFloat() throws Exception { testCall(db, "return apoc.convert.toFloat('true') as value", r -> assertEquals(1.0, r.get("value"))); testCall(db, "return apoc.convert.toFloat(1) as value", r -> assertEquals(1.0, r.get("value"))); testCall(db, "return apoc.convert.toFloat('false') as value", r -> assertEquals(0.0, r.get("value"))); testCall(db, "return apoc.convert.toFloat(0) as value", r -> assertEquals(0.0, r.get("value"))); testCall(db, "return apoc.convert.toFloat('123') as value", r -> assertEquals(123.0, r.get("value"))); testCall(db, "return apoc.convert.toFloat(123) as value", r -> assertEquals(123.0, r.get("value"))); testCall(db, "return apoc.convert.toFloat('123.15') as value", r -> assertEquals(123.15, r.get("value"))); testCall(db, "return apoc.convert.toFloat('123.15') as value", r -> assertEquals(123.15, r.get("value"))); testCall(db, "return apoc.convert.toFloat('0x15') as value", r -> assertEquals(21D, r.get("value"))); testCall(db, "return apoc.convert.toFloat('') as value", r -> assertEquals(null, r.get("value"))); testCall(db, "return apoc.convert.toFloat(null) as value", r -> assertEquals(null, r.get("value"))); }
@UserFunction @Description("apoc.convert.toFloat(value) | tries it's best to convert the value to a float") public Double toFloat(@Name("object") Object obj) { if (obj == null || obj.equals("")) { return null; } Types varType = Types.of(obj); switch (varType) { case FLOAT: case INTEGER: return ((Number) obj).doubleValue(); case STRING: return parseDoubleString((String)obj); case BOOLEAN: return ((boolean) obj) ? 1D : 0D; default: return null; } }
Convert { @UserFunction @Description("apoc.convert.toFloat(value) | tries it's best to convert the value to a float") public Double toFloat(@Name("object") Object obj) { if (obj == null || obj.equals("")) { return null; } Types varType = Types.of(obj); switch (varType) { case FLOAT: case INTEGER: return ((Number) obj).doubleValue(); case STRING: return parseDoubleString((String)obj); case BOOLEAN: return ((boolean) obj) ? 1D : 0D; default: return null; } } }
Convert { @UserFunction @Description("apoc.convert.toFloat(value) | tries it's best to convert the value to a float") public Double toFloat(@Name("object") Object obj) { if (obj == null || obj.equals("")) { return null; } Types varType = Types.of(obj); switch (varType) { case FLOAT: case INTEGER: return ((Number) obj).doubleValue(); case STRING: return parseDoubleString((String)obj); case BOOLEAN: return ((boolean) obj) ? 1D : 0D; default: return null; } }  }
Convert { @UserFunction @Description("apoc.convert.toFloat(value) | tries it's best to convert the value to a float") public Double toFloat(@Name("object") Object obj) { if (obj == null || obj.equals("")) { return null; } Types varType = Types.of(obj); switch (varType) { case FLOAT: case INTEGER: return ((Number) obj).doubleValue(); case STRING: return parseDoubleString((String)obj); case BOOLEAN: return ((boolean) obj) ? 1D : 0D; default: return null; } }  @UserFunction @Description("apoc.convert.toMap(value) | tries it's best to convert the value to a map") Map<String, Object> toMap(@Name("map") Object map); @UserFunction @Description("apoc.convert.toString(value) | tries it's best to convert the value to a string") String toString(@Name("string") Object string); @UserFunction @Description("apoc.convert.toList(value) | tries it's best to convert the value to a list") List<Object> toList(@Name("list") Object list); @UserFunction @Description("apoc.convert.toBoolean(value) | tries it's best to convert the value to a boolean") Boolean toBoolean(@Name("bool") Object bool); @UserFunction @Description("apoc.convert.toNode(value) | tries it's best to convert the value to a node") Node toNode(@Name("node") Object node); @UserFunction @Description("apoc.convert.toRelationship(value) | tries it's best to convert the value to a relationship") Relationship toRelationship(@Name("relationship") Object relationship); @SuppressWarnings("unchecked") @UserFunction @Description("apoc.convert.toSet(value) | tries it's best to convert the value to a set") List<Object> toSet(@Name("list") Object value); @UserFunction @Description("apoc.convert.toIntList(value) | tries it's best to convert " + "the value to a list of integers") List<Long> toIntList(@Name("list") Object list); @UserFunction @Description("apoc.convert.toStringList(value) | tries it's best to convert " + "the value to a list of strings") List<String> toStringList(@Name("list") Object list); @UserFunction @Description("apoc.convert.toBooleanList(value) | tries it's best to convert " + "the value to a list of booleans") List<Boolean> toBooleanList(@Name("list") Object list); @UserFunction @Description("apoc.convert.toNodeList(value) | tries it's best to convert " + "the value to a list of nodes") List<Node> toNodeList(@Name("list") Object list); @UserFunction @Description("apoc.convert.toRelationshipList(value) | tries it's best to convert " + "the value to a list of relationships") List<Relationship> toRelationshipList(@Name("list") Object list); @UserFunction @Description("apoc.convert.toInteger(value) | tries it's best to convert the value to an integer") Long toInteger(@Name("object") Object obj); @UserFunction @Description("apoc.convert.toFloat(value) | tries it's best to convert the value to a float") Double toFloat(@Name("object") Object obj); }
Convert { @UserFunction @Description("apoc.convert.toFloat(value) | tries it's best to convert the value to a float") public Double toFloat(@Name("object") Object obj) { if (obj == null || obj.equals("")) { return null; } Types varType = Types.of(obj); switch (varType) { case FLOAT: case INTEGER: return ((Number) obj).doubleValue(); case STRING: return parseDoubleString((String)obj); case BOOLEAN: return ((boolean) obj) ? 1D : 0D; default: return null; } }  @UserFunction @Description("apoc.convert.toMap(value) | tries it's best to convert the value to a map") Map<String, Object> toMap(@Name("map") Object map); @UserFunction @Description("apoc.convert.toString(value) | tries it's best to convert the value to a string") String toString(@Name("string") Object string); @UserFunction @Description("apoc.convert.toList(value) | tries it's best to convert the value to a list") List<Object> toList(@Name("list") Object list); @UserFunction @Description("apoc.convert.toBoolean(value) | tries it's best to convert the value to a boolean") Boolean toBoolean(@Name("bool") Object bool); @UserFunction @Description("apoc.convert.toNode(value) | tries it's best to convert the value to a node") Node toNode(@Name("node") Object node); @UserFunction @Description("apoc.convert.toRelationship(value) | tries it's best to convert the value to a relationship") Relationship toRelationship(@Name("relationship") Object relationship); @SuppressWarnings("unchecked") @UserFunction @Description("apoc.convert.toSet(value) | tries it's best to convert the value to a set") List<Object> toSet(@Name("list") Object value); @UserFunction @Description("apoc.convert.toIntList(value) | tries it's best to convert " + "the value to a list of integers") List<Long> toIntList(@Name("list") Object list); @UserFunction @Description("apoc.convert.toStringList(value) | tries it's best to convert " + "the value to a list of strings") List<String> toStringList(@Name("list") Object list); @UserFunction @Description("apoc.convert.toBooleanList(value) | tries it's best to convert " + "the value to a list of booleans") List<Boolean> toBooleanList(@Name("list") Object list); @UserFunction @Description("apoc.convert.toNodeList(value) | tries it's best to convert " + "the value to a list of nodes") List<Node> toNodeList(@Name("list") Object list); @UserFunction @Description("apoc.convert.toRelationshipList(value) | tries it's best to convert " + "the value to a list of relationships") List<Relationship> toRelationshipList(@Name("list") Object list); @UserFunction @Description("apoc.convert.toInteger(value) | tries it's best to convert the value to an integer") Long toInteger(@Name("object") Object obj); @UserFunction @Description("apoc.convert.toFloat(value) | tries it's best to convert the value to a float") Double toFloat(@Name("object") Object obj); @Context
    public Log log; }