Use InvariantCulture for bytes
This commit is contained in:
Родитель
69f1371a8b
Коммит
e3cf455bd3
|
@ -8,10 +8,10 @@ namespace Camelotia.Presentation.Tests
|
||||||
{
|
{
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(0, "0B")]
|
[InlineData(0, "0B")]
|
||||||
[InlineData(520400, "520,4KB")]
|
[InlineData(520400, "520.4KB")]
|
||||||
[InlineData(520040000, "520MB")]
|
[InlineData(520040000, "520MB")]
|
||||||
[InlineData(520068000, "520,1MB")]
|
[InlineData(520068000, "520.1MB")]
|
||||||
[InlineData(520185000000, "520,2GB")]
|
[InlineData(520185000000, "520.2GB")]
|
||||||
public void ByteConverterShouldCalculateWithNoPrecisionSupplied(long byteCount, string expectedValue)
|
public void ByteConverterShouldCalculateWithNoPrecisionSupplied(long byteCount, string expectedValue)
|
||||||
{
|
{
|
||||||
var stringValue = ByteConverter.BytesToString(byteCount);
|
var stringValue = ByteConverter.BytesToString(byteCount);
|
||||||
|
@ -21,10 +21,10 @@ namespace Camelotia.Presentation.Tests
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(115, 1, "115B")]
|
[InlineData(115, 1, "115B")]
|
||||||
[InlineData(115, 3, "115B")]
|
[InlineData(115, 3, "115B")]
|
||||||
[InlineData(520348, 3, "520,348KB")]
|
[InlineData(520348, 3, "520.348KB")]
|
||||||
[InlineData(520462400, 3, "520,462MB")]
|
[InlineData(520462400, 3, "520.462MB")]
|
||||||
[InlineData(520573990000, 3, "520,574GB")]
|
[InlineData(520573990000, 3, "520.574GB")]
|
||||||
[InlineData(520124960000, 3, "520,125GB")]
|
[InlineData(520124960000, 3, "520.125GB")]
|
||||||
public void ByteConverterShouldCalculate(long byteCount, int precision, string expectedValue)
|
public void ByteConverterShouldCalculate(long byteCount, int precision, string expectedValue)
|
||||||
{
|
{
|
||||||
var stringValue = ByteConverter.BytesToString(byteCount, precision);
|
var stringValue = ByteConverter.BytesToString(byteCount, precision);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
namespace Camelotia.Services.Models
|
namespace Camelotia.Services.Models
|
||||||
{
|
{
|
||||||
|
@ -13,7 +14,8 @@ namespace Camelotia.Services.Models
|
||||||
var bytes = Math.Abs(byteCount);
|
var bytes = Math.Abs(byteCount);
|
||||||
var place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1000)));
|
var place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1000)));
|
||||||
var num = Math.Round(bytes / Math.Pow(1000, place), decimalPrecision);
|
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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче