Skip to content

Commit

Permalink
ClickHouseDecimal: wrong conversion to integral types (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkWanderer authored Apr 7, 2024
1 parent 39fcbc0 commit 8cece7d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ClickHouse.Client.Tests/Numerics/ClickHouseDecimalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ public void ShouldRoundtripIntoDouble(double @double)
[TestCase(typeof(string))]
public void ShouldConvertToType(Type type)
{
var expected = Convert.ChangeType(5m, type);
var actual = Convert.ChangeType(new ClickHouseDecimal(5m), type);
var expected = Convert.ChangeType(5.00m, type);
var actual = Convert.ChangeType(new ClickHouseDecimal(5.00m), type);
Assert.AreEqual(expected, actual);
}

Expand Down
8 changes: 4 additions & 4 deletions ClickHouse.Client/Numerics/ClickHouseDecimal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,22 @@ public static explicit operator decimal(ClickHouseDecimal value)

public static explicit operator int(ClickHouseDecimal value)
{
return (int)(value.Mantissa * BigInteger.Pow(10, value.Scale));
return (int)(value.Mantissa / BigInteger.Pow(10, value.Scale));
}

public static explicit operator uint(ClickHouseDecimal value)
{
return (uint)(value.Mantissa * BigInteger.Pow(10, value.Scale));
return (uint)(value.Mantissa / BigInteger.Pow(10, value.Scale));
}

public static explicit operator long(ClickHouseDecimal value)
{
return (long)(value.Mantissa * BigInteger.Pow(10, value.Scale));
return (long)(value.Mantissa / BigInteger.Pow(10, value.Scale));
}

public static explicit operator ulong(ClickHouseDecimal value)
{
return (ulong)(value.Mantissa * BigInteger.Pow(10, value.Scale));
return (ulong)(value.Mantissa / BigInteger.Pow(10, value.Scale));
}

public static ClickHouseDecimal operator +(ClickHouseDecimal left, ClickHouseDecimal right)
Expand Down

0 comments on commit 8cece7d

Please sign in to comment.