Last active
April 12, 2019 16:06
-
-
Save InvaderZim85/a0b6a7d15d61f0a807b6029e4ba64c01 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string ConvertFileSize(long size) | |
{ | |
switch (size) | |
{ | |
case long n when (n < 1024): | |
return $"{n} Bytes"; | |
case long n when (n >= 1024 && n < Math.Pow(1024, 2)): | |
return $"{n / 1024:N2} KB"; | |
case long n when (n >= Math.Pow(1024, 2) && n < Math.Pow(1024, 3)): | |
return $"{n / Math.Pow(1024, 2):N2} MB"; | |
case long n when (n >= Math.Pow(1024, 3)): | |
return $"{n / Math.Pow(1024, 3):N2} GB"; | |
default: | |
return size.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment