Skip to content

Commit dd4f61e

Browse files
Trim trailing zeroes from decimal values during JSON serialization.
1 parent 1dc8197 commit dd4f61e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,12 +1631,32 @@ public void AddObjectProperty(string name, object prop, bool includeState, bool
16311631
JsonObj.Put(name, prop);
16321632
}
16331633
}
1634+
else if (prop is decimal)
1635+
{
1636+
JsonObj.Put(name, RemoveInternalTrailingZeroes((decimal)prop));
1637+
}
16341638
else
16351639
{
16361640
JsonObj.Put(name, prop);
16371641
}
16381642
}
16391643
}
1644+
static decimal RemoveInternalTrailingZeroes(decimal dec)
1645+
{
1646+
if (GetDecimalScale(dec) > 0)
1647+
{
1648+
string strdec = dec.ToString(CultureInfo.InvariantCulture);
1649+
return decimal.Parse(strdec.Contains(".") ? strdec.TrimEnd('0').TrimEnd('.') : strdec);
1650+
}
1651+
else
1652+
return dec;
1653+
1654+
}
1655+
static int GetDecimalScale(decimal value)
1656+
{
1657+
int[] bits = decimal.GetBits(value);
1658+
return (bits[3] >> 16) & 0xFF;
1659+
}
16401660
public Object GetJSONObject(bool includeState, bool includeNoInitialized)
16411661
{
16421662
JsonObj.Clear();

0 commit comments

Comments
 (0)