does anybody know about this issue?
# community-help
c
does anybody know about this issue?
j
Ah good ol' floating point arithmetic. Could you open a github issue about this @Claudiu Roman Ardelean?
c
hey, i will tomorrow, in the document the value looks ok in the hits, just on the facets value is the problem
k
@Claudiu Roman Ardelean I'm not able to reproduce this issue. I indexed a single document with a facet field value of
113.4
and facet on the same field during searching. See the screenshot: the response looks fine.
If you can share a small snippet that reproduces this issue, that will help us narrow down the issue.
c
hey @Kishore Nallan but in the document the value of the field "points" is 113.4 and in the facet is returned as 113.400002. Why is this happening?
message has been deleted
k
@Claudiu Roman Ardelean That's because many floating point numbers cannot be represented exactly, so when they are serialized they might have some trailing decimal places at the end. In general, for facets it is better to store price in cents (as integer) instead of a float.
In your original post though, you said that
113.4 is changed to 114.300003
-> such a large difference should not happen. Was that a typo?
c
look at the CB field 63.3 is returned in facet like 63.299999
the thing is i have to do a filter in the sidebar, and i need the exact value
because i will filter by that value
a workaround is to convert everything to int32
k
Yes, it's the same issue. When you convert a number from a floating point representation to string, this can happen unless we know how many decimal places the original precision of the float was. In this case, the best way to work around this issue is to store the float as an integer in cents.
👍 1
c
thanks
like i guessed
k
In the mean time, I will see if there is anything we can do here. It's a notoriously difficult problem because of the way a float is represented.
c
i understand
i will user. integer
k
👍
c
you are doing a good job
🙌 1
k
@Claudiu Roman Ardelean Found a way to fix this. I can cut you a RC build where this is addressed, if you would like.
c
uh
i already used integer
but i can test it
k
No worries, then! Just wanted to check 🙂
c
you guys are so fast 😄
k
😄
c
i hope this community is getting bigger and bigger
🚀 2
e
hey @Kishore Nallan, I'm getting the error `400: {"message": "Field
cost
should be a string or a string array."}` . The actual value is float. What do you think is the issue here?