Start value 5200
HINCRBYFLOAT mykey field 10.43
Result value is:
5210.43000000000000016
Test playground: https://redis.io/commands/hincrbyfloat/
Section example
The same problem at Redis 6 alpine docker image. How to fix it?
Comment From: sundb
This is not a bug, floating precision is different on different platforms.
Comment From: petrixs
@sundb At the same time Redis is a product which used for solving real tasks. Could you imagine situation when this behavior is useful?
Comment From: sundb
@petrixs First, this behavior is not intentional by redis.
It is determined by the platforms and FPU, and the same floating-point number may have different expressions under different platforms or CPU.
This doesn't only happen in redis, just like judging 0.1 + 0.2 == 0.3 in any language on your computer, you will find that it returns false.
Comment From: petrixs
@sundb Is there a way to get the expected float except using hincrby and operating with integers this way?
Comment From: sundb
@petrixs Looks like it doesn't. However, I often encounter this kind of problem in my daily work. In order to avoid the precision deviation between the server and the client, we will multiply the floating decimal by 10000(keep 4 fractional numbers) before communicating, the use is the same, and it will eventually divide by 10000. Not sure if any other have a better practice.
Comment From: petrixs
@sundb thank you