Home > database >  [redis] INCRBYFLOAT methods cause small digital anomalies
[redis] INCRBYFLOAT methods cause small digital anomalies

Time:10-15

Recently found in the process of learning redis INCRBYFLOAT method in string command will have a question, why is this? How to solve?

127.0.0.1:6379 [2] & gt; INCRBYFLOAT amount 500
"500"

127.0.0.1:6379 [2] & gt; INCRBYFLOAT amount 2.1
"502.10000000000000001"

127.0.0.1:6379 [2] & gt; INCRBYFLOAT amount 0.3
"502.39999999999999999"

Some data don't have a problem, some can lead to many decimal places, looks like is greater than 150 will have this kind of problem? !


CodePudding user response:

Due to floating-point calculation accuracy problem in the redis, will lead to such problems, and not be able to avoid a
Solution: suggest need to confirm the accuracy of the zoom multiples with integer incr series accordingly
  • Related