MeineGlock.BytesSizeToHumanReadableFormat
1.0.0
dotnet add package MeineGlock.BytesSizeToHumanReadableFormat --version 1.0.0
NuGet\Install-Package MeineGlock.BytesSizeToHumanReadableFormat -Version 1.0.0
<PackageReference Include="MeineGlock.BytesSizeToHumanReadableFormat" Version="1.0.0" />
paket add MeineGlock.BytesSizeToHumanReadableFormat --version 1.0.0
#r "nuget: MeineGlock.BytesSizeToHumanReadableFormat, 1.0.0"
// Install MeineGlock.BytesSizeToHumanReadableFormat as a Cake Addin #addin nuget:?package=MeineGlock.BytesSizeToHumanReadableFormat&version=1.0.0 // Install MeineGlock.BytesSizeToHumanReadableFormat as a Cake Tool #tool nuget:?package=MeineGlock.BytesSizeToHumanReadableFormat&version=1.0.0
Bytes Size to Human Readable Format
This is a .NET Standard class library that provides an extension for transforming a ulong of bytes into a human-readable format. It is primarily designed for measuring disk sizes. For example, passing 867630342949 will return the string "808.4 GB".
Key features include:
- Localization support via the optional Culture parameter.
- Customizable decimal places (0 to 15).
- Ability to force formatting to a specific unit (e.g., MB, GB, PB).
- Optional thousands separator for readability.
- Handles up to 16 EXABYTES.
Installation
You can install the lastest package via NuGet:
coming soon
Usage
Console.WriteLine("📌 Default Settings:");
foreach (var movie in movies.OrderByDescending(x => x.Size))
{
Console.WriteLine($"{movie.Name} - {movie.Size.BytesToHumanReadableFormat()}");
}
Results
📌 Default Settings:
The Godfather - 16 EB
The Shawshank Redemption - 808.04 GB
The Godfather: Part II - 698.54 GB
The Lord of the Rings - 492.19 GB
Schindler's List - 1001.92 MB
The Dark Knight - 215.65 KB
Pulp Fiction - 0 B
Full Implementation Example (See the console demo)
using System.Globalization;
using BytesSizeToHumanReadableFormat;
Console.WriteLine("Fake Movie Listing With Disk Size!");
Console.WriteLine();
// Create a fake list of movies with their disk size in bytes.
var movies = new List<Movie>
{
new() { Name = "The Shawshank Redemption", Size = 867630342949 },
new() { Name = "The Godfather", Size = 18446744073709551615 },
new() { Name = "The Dark Knight", Size = 220824 },
new() { Name = "The Godfather: Part II", Size = 750052082558 },
new() { Name = "The Lord of the Rings", Size = 528489456732 },
new() { Name = "Pulp Fiction", Size = 0 },
new() { Name = "Schindler's List", Size = 1050591100 },
};
Console.WriteLine("📌 Default Settings:");
foreach (var movie in movies.OrderByDescending(x => x.Size))
{
Console.WriteLine($"{movie.Name} - {movie.Size.BytesToHumanReadableFormat()}");
}
Console.WriteLine();
Console.WriteLine("📌 Using German culture, rounding to 4 decimal places, forcing to MB, and use a thousands seperator:");
CultureInfo culture = new("de-De");
foreach (var movie in movies.OrderByDescending(x => x.Size))
{
Console.WriteLine($"{movie.Name} - {movie.Size.BytesToHumanReadableFormat(culture, RoundToDecimalPlaces.Four, SizeFormats.MB, useThousandsSeparator: true)}");
}
class Movie
{
public string? Name { get; set; }
public ulong Size { get; set; }
}
Results
📌 Default Settings:
The Godfather - 16 EB
The Shawshank Redemption - 808.04 GB
The Godfather: Part II - 698.54 GB
The Lord of the Rings - 492.19 GB
Schindler's List - 1001.92 MB
The Dark Knight - 215.65 KB
Pulp Fiction - 0 B
📌 Using German culture, rounding to 4 decimal places, forcing to MB, and use a thousands seperator:
The Godfather - 17.592.186.044.416 MB
The Shawshank Redemption - 827.436,7742 MB
The Godfather: Part II - 715.305,4071 MB
The Lord of the Rings - 504.006,8214 MB
Schindler's List - 1.001,9217 MB
The Dark Knight - 0,2106 MB
Pulp Fiction - 0 MB
Home Page
https://github.com/meineGlock20/BytesSizeToHumanReadableFormat
License
This project is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 100 | 10/10/2024 |
Initial Release