Use InvariantCulture for bytes

This commit is contained in:
Artyom G 2018-12-15 09:33:07 +03:00
Родитель 69f1371a8b
Коммит e3cf455bd3
2 изменённых файлов: 10 добавлений и 8 удалений

Просмотреть файл

@ -8,10 +8,10 @@ namespace Camelotia.Presentation.Tests
{
[Theory]
[InlineData(0, "0B")]
[InlineData(520400, "520,4KB")]
[InlineData(520400, "520.4KB")]
[InlineData(520040000, "520MB")]
[InlineData(520068000, "520,1MB")]
[InlineData(520185000000, "520,2GB")]
[InlineData(520068000, "520.1MB")]
[InlineData(520185000000, "520.2GB")]
public void ByteConverterShouldCalculateWithNoPrecisionSupplied(long byteCount, string expectedValue)
{
var stringValue = ByteConverter.BytesToString(byteCount);
@ -21,10 +21,10 @@ namespace Camelotia.Presentation.Tests
[Theory]
[InlineData(115, 1, "115B")]
[InlineData(115, 3, "115B")]
[InlineData(520348, 3, "520,348KB")]
[InlineData(520462400, 3, "520,462MB")]
[InlineData(520573990000, 3, "520,574GB")]
[InlineData(520124960000, 3, "520,125GB")]
[InlineData(520348, 3, "520.348KB")]
[InlineData(520462400, 3, "520.462MB")]
[InlineData(520573990000, 3, "520.574GB")]
[InlineData(520124960000, 3, "520.125GB")]
public void ByteConverterShouldCalculate(long byteCount, int precision, string expectedValue)
{
var stringValue = ByteConverter.BytesToString(byteCount, precision);

Просмотреть файл

@ -1,4 +1,5 @@
using System;
using System.Globalization;
namespace Camelotia.Services.Models
{
@ -13,7 +14,8 @@ namespace Camelotia.Services.Models
var bytes = Math.Abs(byteCount);
var place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1000)));
var num = Math.Round(bytes / Math.Pow(1000, place), decimalPrecision);
return (Math.Sign(byteCount) * num) + suf[place];
var digit = Math.Sign(byteCount) * num;
return digit.ToString(CultureInfo.InvariantCulture) + suf[place];
}
}
}