Add first draft unit determination tools

This commit is contained in:
Alexander Stoll 2020-02-07 15:07:29 +01:00
parent 58d2aa7403
commit e07f7f1482
2 changed files with 41 additions and 0 deletions

View file

@ -0,0 +1,21 @@
function Get-UnitPrefixIEC()
{
param(
[single]$Value
);
If ( $Value / [math]::Pow(2, 50) -ge 1 ) {
return 'PiB'
} elseif ( $Value / [math]::Pow(2, 40) -ge 1 ) {
return 'TiB'
} elseif ( $Value / [math]::Pow(2, 30) -ge 1 ) {
return 'GiB'
} elseif ( $Value / [math]::Pow(2, 20) -ge 1 ) {
return 'MiB'
} elseif ( $Value / [math]::Pow(2, 10) -ge 1 ) {
return 'KiB'
} else {
return 'B'
}
}

View file

@ -0,0 +1,20 @@
function Get-UnitPrefixSI()
{
param(
[single]$Value
);
If ( $Value / [math]::Pow(10, 15) -ge 1 ) {
return 'PB'
} elseif ( $Value / [math]::Pow(10, 12) -ge 1 ) {
return 'TB'
} elseif ( $Value / [math]::Pow(10, 9) -ge 1 ) {
return 'GB'
} elseif ( $Value / [math]::Pow(10, 6) -ge 1 ) {
return 'MB'
} elseif ( $Value / [math]::Pow(10, 3) -ge 1 ) {
return 'KB'
} else {
return 'B'
}
}