Skip to content

Commit f0bf633

Browse files
Per Kopsperkops
authored andcommitted
refactor: improve readability of nested Math.Min in SqlDecimalExtensions
Replace nested Math.Min calls with explicit intermediate variable and clarifying comments. This makes the scale calculation logic more readable by breaking down the three constraints being evaluated: 1. Actual SqlDecimal scale 2. .NET decimal maximum scale (27) 3. Available scale given integer part size
1 parent 947a74f commit f0bf633

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Atc.Kusto/Extensions/SqlDecimalExtensions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@ public static decimal ToDecimal(this SqlDecimal sqlDecimal)
5252
}
5353

5454
var maxAvailableScale = DotNetDecimalMaxPrecision - integerDigits;
55-
var targetScale = System.Math.Min(sqlDecimal.Scale, System.Math.Min(DotNetDecimalMaxScale, maxAvailableScale));
55+
56+
// Calculate target scale as the minimum of all constraints:
57+
// 1. The actual scale from SqlDecimal
58+
// 2. .NET decimal's maximum scale (27)
59+
// 3. Available scale given the integer part size
60+
var scaleConstrainedByDotNet = System.Math.Min((int)sqlDecimal.Scale, DotNetDecimalMaxScale);
61+
var targetScale = System.Math.Min(scaleConstrainedByDotNet, maxAvailableScale);
62+
5663
var targetPrecision = System.Math.Min(sqlDecimal.Precision, integerDigits + targetScale);
5764

5865
if (targetPrecision != sqlDecimal.Precision || targetScale != sqlDecimal.Scale)

0 commit comments

Comments
 (0)