var siPrefixTable … var revSIPrefixTable … // revfmap reverses the map and precomputes the power multiplier func revfmap(in map[float64]string) map[string]float64 { … } var riParseRegex … func init() { … } // ComputeSI finds the most appropriate SI prefix for the given number // and returns the prefix along with the value adjusted to be within // that prefix. // // See also: SI, ParseSI. // // e.g. ComputeSI(2.2345e-12) -> (2.2345, "p") func ComputeSI(input float64) (float64, string) { … } // SI returns a string with default formatting. // // SI uses Ftoa to format float value, removing trailing zeros. // // See also: ComputeSI, ParseSI. // // e.g. SI(1000000, "B") -> 1 MB // e.g. SI(2.2345e-12, "F") -> 2.2345 pF func SI(input float64, unit string) string { … } // SIWithDigits works like SI but limits the resulting string to the // given number of decimal places. // // e.g. SIWithDigits(1000000, 0, "B") -> 1 MB // e.g. SIWithDigits(2.2345e-12, 2, "F") -> 2.23 pF func SIWithDigits(input float64, decimals int, unit string) string { … } var errInvalid … // ParseSI parses an SI string back into the number and unit. // // See also: SI, ComputeSI. // // e.g. ParseSI("2.2345 pF") -> (2.2345e-12, "F", nil) func ParseSI(input string) (float64, string, error) { … }