Ejemplo n.º 1
0
        private void CheckConvertOneWay(long value1, SizeUnit unit1, long value2, SizeUnit unit2)
        {
            double convertedValue2 = SizeUnit.Convert(value1, unit1, unit2);

            output.WriteLine($"Expected: {value1} {unit1.Name} = {value2} {unit2.Name}");
            output.WriteLine($"Actual: {value1} {unit1.Name} = {convertedValue2} {unit2.Name}");
            output.WriteLine("");
            Assert.Equal(value2, convertedValue2, 4);
        }
Ejemplo n.º 2
0
        public static string ToSizeStr(this long value, SizeUnit unit = null, int unitNameWidth = 1, bool showUnit = true)
        {
            unit = unit ?? SizeUnit.GetBestSizeUnit(value);
            var unitValue = SizeUnit.Convert(value, SizeUnit.B, unit);

            if (showUnit)
            {
                string unitName = unit.Name.PadLeft(unitNameWidth);
                return(string.Format(HostEnvironmentInfo.MainCultureInfo, "{0:0.##} {1}", unitValue, unitName));
            }

            return(string.Format(HostEnvironmentInfo.MainCultureInfo, "{0:0.##}", unitValue));
        }
Ejemplo n.º 3
0
            public string ToString(SizeUnit sizeUnit)
            {
                var unitValue = SizeUnit.Convert(Bytes, SizeUnit.B, sizeUnit);

                return(unitValue.ToString("0.##", CultureInfo.InvariantCulture));
            }