Skip to content

Commit 5195069

Browse files
committed
FIX: decimal extensions - to sep str
1 parent abf5add commit 5195069

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

Src/Libs/Ws.Shared/Extensions/DecimalExtensions.cs

+3-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ namespace Ws.Shared.Extensions;
44

55
public static class DecimalExtensions
66
{
7-
public static string ToSepStr(this decimal d, string? separator = null)
7+
public static string ToSepStr(this decimal d, char? separator = null)
88
{
9-
if (!string.IsNullOrEmpty(separator))
10-
return d.ToString($"0.000{separator}");
11-
129
string systemDecimalSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
13-
return d.ToString($"0.000{systemDecimalSeparator}").Replace(systemDecimalSeparator, string.Empty);
10+
return d.ToString("0.000")
11+
.Replace(systemDecimalSeparator, separator != null ? separator.ToString() : string.Empty);
1412
}
15-
1613
}

Src/Services/Ws.Labels.Service/Generate/Models/Variables/TemplateVars.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public class TemplateVars(
4242

4343
#region Other
4444

45-
public readonly string WeightNet = weightNet.ToSepStr(",");
46-
public readonly string WeightGross = weightGross.ToSepStr(",");
45+
public readonly string WeightNet = weightNet.ToSepStr(',');
46+
public readonly string WeightGross = weightGross.ToSepStr(',');
4747

4848
public readonly ushort BundleCount = bundleCount;
4949
public readonly string Kneading = $"{kneading:D3}";

Src/Tests/Ws.Shared.Tests/Extensions/DecimalExtensionsTests.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ namespace Ws.Shared.Tests.Extensions;
66
[SuppressMessage("Usage", "xUnit1012:Null should only be used for nullable parameters")]
77
public class DecimalExtensionsTests
88
{
9-
public static TheoryData<decimal, string, string> TestSepData()
9+
public static TheoryData<decimal, char?, string> TestSepData()
1010
{
1111
return new()
1212
{
13-
{ 234567.89m, "", "23456789" },
14-
{ 1.89m, "/", "1/89" },
15-
{ 100.00m, ",", "100,00" },
16-
{ 999.99m, ".", "999.99" },
17-
{ 42.42m, "-", "42-42" }
13+
{ 234567.89m, null, "234567890" },
14+
{ 1.89m, '/', "1/890" },
15+
{ 100.00m, ',', "100,000" },
16+
{ 999.99m, '.', "999.990" },
17+
{ 42.42m, '-', "42-420" }
1818
};
1919
}
2020

2121
[Theory]
2222
[MemberData(nameof(TestSepData))]
23-
public void Test_Decimal_Sep(decimal input, string sep, string expected)
23+
public void Test_Decimal_Sep(decimal input, char? sep, string expected)
2424
{
2525
input.ToSepStr(sep).Should().Be(expected);
2626
}

0 commit comments

Comments
 (0)