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); }
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)); }
public string ToString(SizeUnit sizeUnit) { var unitValue = SizeUnit.Convert(Bytes, SizeUnit.B, sizeUnit); return(unitValue.ToString("0.##", CultureInfo.InvariantCulture)); }