Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float to Double Conversion Issue in Values class #1561

Open
garvit-joshi opened this issue Jul 13, 2024 · 2 comments
Open

Float to Double Conversion Issue in Values class #1561

garvit-joshi opened this issue Jul 13, 2024 · 2 comments

Comments

@garvit-joshi
Copy link

garvit-joshi commented Jul 13, 2024

Neo4j Version: 5.21.2
Neo4j Mode
Single instance
Driver Version: 5.22.0
Operating System
Apple M2 Pro [Version 14.5 Sonoma]

Steps to reproduce

Create a float variable with a value that can't be precisely represented in binary (e.g., 17.3f)
Pass this value to a method that expects a double
Observe the value inside the method

Expected behavior

The float value should be converted to its exact double representation without loss of precision.
Actual behavior
The float value, when converted to double, shows more decimal places and a slightly different value. For example, 17.3f becomes 17.299999237060547.
Code Example:

public class Example {
    public static void main(String[] args) {
        float b = 17.3f;
        hello((float) b);
    }

    public static void hello(double a) {
        System.out.println("A: " + a);
    }
}

Output:
A: 17.299999237060547

Additional Context

This issue occurs in the Values.value(Object value) method:

public static Value value(Object value) {
    // ...
    if (value instanceof Double) {
        return value((double) value);
    }
    if (value instanceof Float) {
        return value((float) value);
    }
    // ...
}

The conversion from float to double may lead to a change in the visible decimal representation of the number.

Impact:

This issue affects the accuracy of data stored in Neo4j when working with float values, potentially leading to unexpected results in queries.

@garvit-joshi garvit-joshi changed the title Float to Double Conversion Issue in Spring Data Neo4j Float to Double Conversion Issue in Values class Jul 13, 2024
@garvit-joshi
Copy link
Author

Hi @injectives,
Would this be considered an issue or not?
If It is, could I work on it?

@garvit-joshi
Copy link
Author

Hi @injectives ,
Any update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant