Argentini.Halide.H3Text.UnFormatFileSize C# (CSharp) Method

UnFormatFileSize() public static method

Converts a file size string into a number of equivalent bytes. Used to convert strings like "115KB" to a number or actual bytes.
public static UnFormatFileSize ( string fileSize ) : Decimal
fileSize string String file size to convert to a number of bytes /// (e.g. "103kb", "15 MB", "1TB", "37.6GB", et al.).
return Decimal
        public static Decimal UnFormatFileSize(string fileSize)
        {
            Decimal retVal = 0;
            Decimal multiplier = 0;
            string value = fileSize.ToLower().Replace(",", "").Trim();

            if (value.EndsWith("kb")) { value = value.Replace("kb", "").Trim(); multiplier = 1024; }
            if (value.EndsWith("mb")) { value = value.Replace("mb", "").Trim(); multiplier = 1048576; }
            if (value.EndsWith("gb")) { value = value.Replace("gb", "").Trim(); multiplier = 1073741824; }
            if (value.EndsWith("tb")) { value = value.Replace("tb", "").Trim(); multiplier = 1099511627776; }
            if (value.EndsWith("pb")) { value = value.Replace("pb", "").Trim(); multiplier = 1125899906842624; }

            if (H3Identify.IsNumeric(value))
            {
                if (!(Convert.ToDecimal(value) > 9 && multiplier == 1125899906842624))
                {
                    retVal = Convert.ToDecimal(value) * multiplier;
                }
            }

            return retVal;
        }