diff --git a/functions/bytes_to_size.pp b/functions/bytes_to_size.pp index 4c664d79..7bbf4b98 100644 --- a/functions/bytes_to_size.pp +++ b/functions/bytes_to_size.pp @@ -2,6 +2,7 @@ function lvm::bytes_to_size ( Numeric $size, ) { $units = { + 'b' => 1, 'k' => 1024, 'm' => 1048576, 'g' => 1073741824, @@ -18,7 +19,7 @@ function lvm::bytes_to_size ( # Use the last unit $largest_unit = $remaining_units.keys[-1] - $value = ($size / $units[$largest_unit]) + $value = (Float($size) / $units[$largest_unit]) # # Return the string "${value}${largest_unit}" diff --git a/functions/size_to_bytes.pp b/functions/size_to_bytes.pp index b2190321..5c2698d6 100644 --- a/functions/size_to_bytes.pp +++ b/functions/size_to_bytes.pp @@ -2,6 +2,7 @@ function lvm::size_to_bytes ( String $size, ) { $units = { + 'B' => 1, 'K' => 1024, 'M' => 1048576, 'G' => 1073741824, @@ -10,7 +11,7 @@ function lvm::size_to_bytes ( 'E' => 1.1529215e18, } # Check if the size is valid and if so, extract the units - if $size =~ /^([0-9]+(\.[0-9]+)?)([KMGTPEkmgtpe])/ { + if $size =~ /^([0-9]+(\.[0-9]+)?)([BKMGTPEbkmgtpe])/ { $unit = String($3, '%u') # Store the units in uppercase $number = Float($1) # Store the number as a float