StackExchange / StackExchange/StackExchange.Redis
StackExchange.Redis.Format Double digits question
Open
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 6.2k
- Forks
- 1.6k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 43
Description
I am using this function and the result will always be unexpected
double StringIncrement(RedisKey key, double value, CommandFlags flags = CommandFlags.None)
var stringIncrement= StringIncrement("StringIncrement", 2.2) // 2.2000000000000002
So I went to check the problem, it might be double 15 digits
but when outputting 17 digits
var redisValue= (RedisValue)2.2;
var result = redisValue.ToString(); // 2.2000000000000002
"StackExchange.Redis.Format" ToString(double value)
internal static string ToString(double value)
{
if (double.IsInfinity(value))
{
if (double.IsPositiveInfinity(value)) return "+inf";
if (double.IsNegativeInfinity(value)) return "-inf";
}
return value.ToString("G17", NumberFormatInfo.InvariantInfo); <= this
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with StackExchange.Redis.Format.ToString(double) and the RedisValue conversion shown in the issue, then reproduce the 2.2 case through StringIncrement and RedisValue.ToString. Done means the intended numeric precision is established and the reported unexpected representation is resolved or documented with a verified behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, redis
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100