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

Issue with small number as value ie 1.222e-11 or 0.00000000001222 #1626

Open
konstantinosGombakis opened this issue Jun 12, 2024 · 1 comment
Assignees
Labels

Comments

@konstantinosGombakis
Copy link

I have a strange issue. I have the following json as payload:

[{
    "id": "urn:ngsi-ld:test_small_number",
    "type": "test",
    "Category1": {
        "type": "Property",
        "value": 1.222e-11,
        "observedAt": "2024-01-11T10:00:07.446Z"
    },
    "Category2": {
        "type": "Property",
        "value": 0.00000000001222,
        "observedAt": "2024-01-11T10:00:07.446Z"
    },
    "Category3": {
        "type": "Property",
        "value": "0.00000000001222",
        "observedAt": "2024-01-11T10:00:07.446Z"
    }
}]

The data (Category1 and Category2) are saved OK (as double) in the mongoDB
image

when i request the data from the Orion-LD i get 0 for the Category1 and 2:

{
  "@context": "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.6.jsonld",
  "id": "urn:ngsi-ld:test_small_number",
  "type": "test",
  "Category1": {
    "type": "Property",
    "value": **0**,
    "observedAt": "2024-01-11T10:00:07.446Z"
  },
  "Category2": {
    "type": "Property",
    "value": **0**,
    "observedAt": "2024-01-11T10:00:07.446Z"
  },
  "Category3": {
    "type": "Property",
    "value": "0.00000000001222",
    "observedAt": "2024-01-11T10:00:07.446Z"
  }
}

Is these a normal operation, so i have to send small numbers as strings?

@kzangeli
Copy link
Collaborator

Is these a normal operation, so i have to send small numbers as strings

Yeah, sorry about that. A CPU isn't really apt to deal with floating point numbers.
I often see things like 1.45 being converted to 1.44999999999999999.
Only thing I could really do about it would be to store the floating point both as a string and a floating point. Use the floating point value for comparisons and the "exact" string value for responses. But, I haven't implemented that, sorry.
Did consider it but never got down to really implement it.

I'd propose to change the "unit" - use for example microseconds instead of seconds, things like that.

@kzangeli kzangeli self-assigned this Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants