If INCRBYFLOAT in Valkey® on a Mac replies with a number like this when you added 9.99, nothing is broken. The extra digits come from how Macs with Apple silicon store decimal numbers, and whole cents avoid them.
"9.99000000000000021"
What I Was Doing
I was writing Valkey Tutorial — Part 4: Strings and Counters on a Mac with Apple silicon and macOS 26, running Valkey 9.2, and adding up a bookshop’s takings with INCRBYFLOAT: a sale of 9.99, then one of 22.50.
What I Expected
9.99, then 32.49. Valkey’s INCRBYFLOAT documentation (opens in a new tab) shows short results, such as 10.6.
What I Got
INCRBYFLOAT revenue:today 9.99
"9.99000000000000021"
INCRBYFLOAT revenue:today 22.5
"32.49000000000000199"

What I Checked
I ran the example from the INCRBYFLOAT documentation on the same Mac. The documentation shows "10.6":
SET mykey 10.50
OK
INCRBYFLOAT mykey 0.1
"10.59999999999999964"
Valkey’s own example gives a longer number here too, so the digits come from the computer, not from my values. Two official sources explain it:
- Valkey’s source code (opens in a new tab) adds in the C type
long doubleand prints 17 digits after the decimal point (opens in a new tab), then drops the zeros at the end. A comment there says 17 digits show most small decimals exactly as typed “with 128 bit floats”. - Apple’s Writing ARM64 code for Apple platforms (opens in a new tab) says that on Apple silicon,
long doubleis identical to the ordinary 64-bitdouble.
Why It Happens
A computer stores decimal numbers in binary, and most of them, like 9.99, can’t be stored exactly: the stored value is off by a tiny amount. On a Mac with Apple silicon, Valkey works with 64-bit numbers, and printing 17 digits after the point is enough to show that tiny difference: 9.99 comes back as 9.99000000000000021.
Valkey saves the same text it replies with, so the extra digits stay in the key and travel into every later total.
The Fix
Count Money in Whole Cents with INCRBY
Store amounts as whole numbers of cents. INCRBY works on whole numbers, which Valkey keeps exactly, as its INCR documentation (opens in a new tab) explains. Use a new key, because INCRBY refuses a key that holds a decimal:
INCRBY revenue:today 1
(error) ERR value is not an integer or out of range
INCRBY revenue:today:cents 999
(integer) 999
INCRBY revenue:today:cents 2250
(integer) 3249
GET revenue:today:cents
"3249"
3249 cents is 32.49. Your app divides by 100 only when it shows the amount.
Or Round the Number When You Show It
If you keep INCRBYFLOAT, round the result to the decimals you need when your app reads it. The value in Valkey keeps the extra digits.
After the Fix

The total is a whole number of cents, with no extra digits.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Comparing an INCRBYFLOAT result with an exact amount such as 32.49 | The comparison fails, because the stored value is 32.49000000000000199 | Count whole cents with INCRBY |
Switching to INCRBY on the old key | It refuses the decimal already stored there | Start a new key, such as revenue:today:cents |
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
"9.99000000000000021" or "10.59999999999999964" | INCRBYFLOAT on a Mac with Apple silicon | Count whole cents with INCRBY, or round when you show the value |
(error) ERR value is not an integer or out of range | The key holds a decimal from INCRBYFLOAT | Use a new key for the whole-cent count |
FAQ
Is the stored amount wrong?
Only by about 0.0000000000000002, far less than a cent. But it’s saved in the key, so totals carry it along and exact comparisons fail.
Does INCRBY have the same problem?
No. INCRBY works on 64-bit whole numbers, which binary stores exactly.
Conclusion
On a Mac with Apple silicon, INCRBYFLOAT replies with 17 digits after the point, which shows the tiny rounding of numbers like 9.99. Count money in whole cents with INCRBY, and divide by 100 only when you show it.
Additional Resources
- INCRBYFLOAT (opens in a new tab)
- INCRBY (opens in a new tab)
- Valkey source: incrbyfloatCommand (opens in a new tab)
- Valkey source: ld2string (opens in a new tab)
- Apple: Writing ARM64 code for Apple platforms (opens in a new tab)
Related
- Valkey Tutorial — Part 4: Strings and Counters
- How to Increment a Decimal Number in Valkey (INCRBYFLOAT)
Valkey® is a registered trademark of LF Projects, LLC. Redis® is a registered trademark of Redis Ltd. Any rights therein are reserved to Redis Ltd. Other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with the Valkey project, LF Projects or Redis Ltd., and isn’t endorsed, supported or certified by them.
0 comments