From a89ce64a045503f4fd56d6aeaf9f694218a72903 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs b/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs index d19290f3..1d4993b3 100644 --- a/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs +++ b/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs @@ -868,7 +868,11 @@ private static string UserAttributeValueToString(object attributeValue) } else if (attributeValue.TryConvertNumericToDouble(out var number)) { - return number.ToString(CultureInfo.InvariantCulture).Replace("E", "e"); + var abs = Math.Abs(number); + var format = 1e-7 < abs && abs < 1e21 + ? "0.#################" + : "0.#################e+0"; + return number.ToString(format, CultureInfo.InvariantCulture); } else if (attributeValue.TryConvertDateTimeToDateTimeOffset(out var dateTimeOffset)) {