Skip to content

Commit

Permalink
[BDB-12] Fix double to string culture difference
Browse files Browse the repository at this point in the history
  • Loading branch information
phamhongphuc1403 committed Aug 16, 2024
1 parent 05a3d4a commit b4a1261
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BuildingBlock.Core.Domain.Rules.Abstractions;
using BuildingBlock.Core.Domain.Shared.Utils;

namespace BuildingBlock.Core.Domain.Rules.Implementations;

Expand Down Expand Up @@ -45,7 +46,8 @@ public bool IsBroken()
var valueName = _valueName is not null ? $"{_valueName}: " : string.Empty;
var compareValueName = _compareValueName is not null ? $"{_compareValueName}: " : string.Empty;

Message = $"{valueName}{_value} must be greater than {compareValueName}{_compareValue}.";
Message =
$"{valueName}{DoubleUtility.ToString(Convert.ToDouble(_value))} must be greater than {compareValueName}{DoubleUtility.ToString(Convert.ToDouble(_compareValue))}.";

return true;
}
Expand Down
13 changes: 13 additions & 0 deletions Core/BuildingBlock.Core.Domain/Shared/Utils/DoubleUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Globalization;

namespace BuildingBlock.Core.Domain.Shared.Utils;

public static class DoubleUtility
{
public static string ToString(double value)
{
var valueString = value.ToString(CultureInfo.InvariantCulture);

return valueString.Replace('.', ',');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using BuildingBlock.Core.Domain.Shared.Utils;
using FluentAssertions;

namespace Tests.Core.Domain.Shared.Utils;

public class DoubleUtilityTest
{
public class ToString
{
[Fact]
public void ShouldConvertDoubleWithDot()
{
var actualData = DoubleUtility.ToString(1.1);

actualData.Should().Be("1,1");
}
}
}

0 comments on commit b4a1261

Please sign in to comment.