### Functions ###
Four functions provide conversions between scalar numeric values and strings with coefficients and prefixes, e.g.: 1000 -> '1 k' and '1 k' -> 1000.
The functions are:
# binum: Binary prefixed string => scalar numeric.
# bipre: Scalar numeric => Binary prefixed string.
# sinum: SI (metric) prefixed string => scalar numeric.
# sipre: Scalar numeric => SI (metric) prefixed string.
Numeric to String:
# Prefix may be selected to be either the full name or the symbol (symbol is default).
# Coefficient's significant figures may be selected (four is default).
# Function automatically uses the most suitable prefix.
String to Numeric:
# Prefix may be automatically detected as name or symbol, or user selected.
# Coefficient format allows +/-, decimal and e-notation.
# Also returns any units that follow the prefix.
### Examples ###
sipre(1000)
ans = '1 k'
sinum('1 k')
ans = 1000
bipre(1024)
ans = '1 Ki'
binum('1 Ki')
ans = 1024
['Power: ',sipre(200*1000^2,[],true),'watt']
ans = 'Power: 200 megawatt'
[val,uni] = sinum('Power: 200 megawatt')
val = 200000000
uni = 'watt'
['Memory: ',bipre(200*1024^2,[],true),'byte']
ans = 'Memory: 200 mebibyte'
[val,uni] = binum('Memory: 200 mebibyte')
val = 209715200
uni = 'byte'
### SI Prefixes (Metric/Engineering) ###
Magnitude | Symbol / Name
1000^-8 | y / yocto
1000^-7 | z / zepto
1000^-6 | a / atto
1000^-5 | f / femto
1000^-4 | p / pico
1000^-3 | n / nano
1000^-2 | u / micro
1000^-1 | m / milli
1000^0 |
1000^1 | k / kilo
1000^2 | M / mega
1000^3 | G / giga
1000^4 | T / tera
1000^5 | P / peta
1000^6 | E / exa
1000^7 | Z / zetta
1000^8 | Y / yotta
### Binary Prefixes (IEC 60027-2 A.2 and ISO/IEC 80000-13:2008) ###
Magnitude | Symbol / Name
1024^0 |
1024^1 | Ki / kibi
1024^2 | Mi / mebi
1024^3 | Gi / gibi
1024^4 | Ti / tebi
1024^5 | Pi / pebi
1024^6 | Ei / exbi
1024^7 | Zi / zebi
1024^8 | Yi / yobi
### Notes ###
Compared to similar functions available on File Exchange, these functions have the correct:
(Num->Str)
# Space character between the coefficient and the prefix.
# Space character after the coefficient, even if no prefix (try 1).
# Significant figure rounding (try 0.99 or 999E3, with 1 significant figure).
# No prefix for zero and values outside the prefix range (try 0, Inf, 1E30).
(Str->Num)
# Symbol upper/lowercase.
# Conversion of negative strings (try '-1').
# Conversion of E-notation values (try '1E0', '1E0 k', '1E30'). |