Skip to content

Commit

Permalink
Merge pull request #92 from epam/tostring-restore
Browse files Browse the repository at this point in the history
toString restore, add toFloatString
  • Loading branch information
agdavydov81 authored Apr 11, 2024
2 parents cecb163 + 38839f1 commit 303f622
Show file tree
Hide file tree
Showing 15 changed files with 786 additions and 315 deletions.
42 changes: 42 additions & 0 deletions csharp/EPAM.Deltix.DFP.Test/Decimal64Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,48 @@ private static void TestToDecimalAndBackCase(long mantissa, int exp)
throw new Exception($"TestToDecimalAndBackCase({mantissa}L, {exp}); // d1(={d0}) != d2(={d2})");
}

private class ToStringData
{
public Decimal64 TestValue;
public string NormalOut;
public string FloatOut;

public ToStringData(Decimal64 testValue, string normalOut, string floatOut)
{
this.TestValue = testValue;
this.NormalOut = normalOut;
this.FloatOut = floatOut;
}
}

[Test]
public void Issue91ToFloatString()
{
var testCases = new ToStringData[]
{
new ToStringData(Decimal64.FromFixedPoint(14L, 0), "14", "14.0"),
new ToStringData(Decimal64.FromFixedPoint(140000000000L, 10), "14", "14.0"),
new ToStringData(Decimal64.Zero, "0", "0.0")
};

foreach(var testCase in testCases)
{
var testValue = testCase.TestValue;
Assert.AreEqual(testCase.NormalOut, testValue.ToString());
Assert.AreEqual(testCase.FloatOut, testValue.ToFloatString());

{
var sb = new StringBuilder();
Assert.AreEqual(testCase.NormalOut, testValue.AppendTo(sb).ToString());
}

{
var sb = new StringBuilder();
Assert.AreEqual(testCase.FloatOut, testValue.FloatAppendTo(sb).ToString());
}
}
}

readonly int N = 5000000;

static void Main()
Expand Down
29 changes: 25 additions & 4 deletions csharp/EPAM.Deltix.DFP/Decimal64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ internal Decimal64(UInt64 value)

public override String ToString()
{
return DotNetImpl.ToString(Bits, DecimalMarkDefault);
return DotNetImpl.ToString(Bits, DecimalMarkDefault, false);
}

public String ToString(char decimalMark)
{
return DotNetImpl.ToString(Bits, decimalMark);
return DotNetImpl.ToString(Bits, decimalMark, false);
//return ((Double)this).ToString(CultureInfo.InvariantCulture);
}

Expand Down Expand Up @@ -1036,14 +1036,24 @@ public String ToScientificString(char decimalMark)
return DotNetImpl.ToScientificString(Bits, decimalMark);
}

public String ToFloatString()
{
return DotNetImpl.ToString(Bits, DecimalMarkDefault, true);
}

public String ToFloatString(char decimalMark)
{
return DotNetImpl.ToString(Bits, decimalMark, true);
}

public StringBuilder AppendTo(StringBuilder text)
{
return DotNetImpl.AppendTo(Bits, DecimalMarkDefault, text);
return DotNetImpl.AppendTo(Bits, DecimalMarkDefault, false, text);
}

public StringBuilder AppendTo(char decimalMark, StringBuilder text)
{
return DotNetImpl.AppendTo(Bits, decimalMark, text);
return DotNetImpl.AppendTo(Bits, decimalMark, false, text);
}

public StringBuilder ScientificAppendTo(StringBuilder text)
Expand All @@ -1056,6 +1066,17 @@ public StringBuilder ScientificAppendTo(char decimalMark, StringBuilder text)
return DotNetImpl.ScientificAppendTo(Bits, decimalMark, text);
}

public StringBuilder FloatAppendTo(StringBuilder text)
{
return DotNetImpl.AppendTo(Bits, DecimalMarkDefault, true, text);
}

public StringBuilder FloatAppendTo(char decimalMark, StringBuilder text)
{
return DotNetImpl.AppendTo(Bits, decimalMark, true, text);
}


#endregion

#region IComparable<> Interface implementation
Expand Down
Loading

0 comments on commit 303f622

Please sign in to comment.