From 23f0a2be60a1a807b132b111d6ff3ea00fdfb8cd Mon Sep 17 00:00:00 2001 From: Adam Simon Date: Fri, 2 Feb 2024 10:03:12 +0100 Subject: [PATCH] Improve number to canonical string formatting --- src/ConfigCatClient/Evaluation/RolloutEvaluator.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs b/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs index d19290f3..bcaf5596 100644 --- a/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs +++ b/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs @@ -868,7 +868,10 @@ private static string UserAttributeValueToString(object attributeValue) } else if (attributeValue.TryConvertNumericToDouble(out var number)) { - return number.ToString(CultureInfo.InvariantCulture).Replace("E", "e"); + var format = Math.Abs(number) is > 1e-7 and < 1e21 + ? "0.#################" + : "0.#################e+0"; + return number.ToString(format, CultureInfo.InvariantCulture); } else if (attributeValue.TryConvertDateTimeToDateTimeOffset(out var dateTimeOffset)) {