Documentation
¶
Overview ¶
Package numfmt renders numbers the way spreadsheets show them: number format patterns as in Sheets' custom number formats and TEXT(), General's shortest form, rounding on the 15 significant digits users see, and the serial day numbers dates and times are stored as. It knows nothing of cells or sheets.
Index ¶
- Variables
- func Accounting(v float64, dec, width int) (string, bool)
- func AccountingIn(v float64, dec, width int, loc *locale.Locale) (string, bool)
- func AddMonths(y, m, n int) (int, int)
- func AdjustDecimals(pat string, delta int) string
- func Civil(serial int64) (y, m, d int)
- func DateSerial(y, m, d int) float64
- func DaysIn(y, m int) int
- func Entered(s string) string
- func Fixed(x float64, n int, mode Rounding) (whole, frac string)
- func Format(v float64, pat string) string
- func FormatIn(v float64, pat string, loc *locale.Locale) string
- func General(v float64) string
- func GeneralFit(v float64, width int) string
- func GeneralFitIn(v float64, width int, loc *locale.Locale) string
- func GeneralIn(v float64, loc *locale.Locale) string
- func Localize(s string, loc *locale.Locale) string
- func Round(x float64, places int, mode Rounding) float64
- func SerialOf(t time.Time) float64
- func Size(v float64, dec int) string
- func SizeIn(v float64, dec int, loc *locale.Locale) string
- func SplitSerial(v float64) (days int64, secs int)
- func TimeSerial(h, m int, s float64) float64
- func Weekday(serial int64) int
- type Rounding
Constants ¶
This section is empty.
Variables ¶
var ( MonthNames = [...]string{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"} DayNames = [...]string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"} )
Functions ¶
func Accounting ¶
Accounting lays out Sheets' Accounting format with dec decimals in width columns: the $ at the left, the number right-aligned with room for a closing parenthesis, negatives in parentheses and zero as a dash. It reports false when the number doesn't fit.
func AccountingIn ¶ added in v0.3.0
AccountingIn is Accounting as shown in loc: its separators, and its currency symbol at the left of the cell, or after the number where loc writes the symbol after it ("1.234,56 € ").
func AddMonths ¶
AddMonths adds n months to month m of year y, returning a month from 1 to 12 and the year it falls in. m itself may be out of range.
func AdjustDecimals ¶
AdjustDecimals adds (delta > 0) or removes zeros after the decimal point of every section of a number pattern, as Sheets' Increase and Decrease decimal places do. Date and time patterns are returned unchanged.
func DateSerial ¶
DateSerial returns the serial of a date; month and day overflow into the next month or year, as DATE() allows.
func Entered ¶ added in v0.4.0
Entered keeps the first 15 significant digits of a number written in decimal (digits, a point, an exponent) and makes the digits after them zeros, as Sheets and Excel do with a number typed into a formula: =123456789012345678 is 123456789012345000. Text with no more than 15 digits comes back as it is. Numbers typed into cells keep every digit, as files and imports write them with 17 to round-trip.
func Fixed ¶
Fixed renders |x| rounded to n decimal places (n may be negative) as its integer digits (no leading zeros, "" for zero) and exactly n decimal digits. It works on the 15 significant digits spreadsheets show, so 1.005 rounds to 1.01 as users expect rather than to the 1.00 its binary value would give.
func FormatIn ¶ added in v0.3.0
FormatIn renders v with a number format pattern as shown in loc: the pattern is written as in en-US ("#,##0.00") and the number shows loc's decimal and thousands separators ("1.234,50" in de-DE).
func General ¶
General renders a number the way Sheets shows it in General format and in text: up to 15 significant digits, no exponent for ordinary magnitudes.
func GeneralFit ¶
GeneralFit renders v in General format within width columns: as many digits as fit, rounding decimals first, then scientific notation, then #s.
func GeneralFitIn ¶ added in v0.3.0
GeneralFitIn is GeneralFit as shown in loc.
func Localize ¶ added in v0.3.0
Localize writes a number in General's form (digits, a point, an exponent, no grouping) with loc's decimal separator.
func Round ¶
Round rounds x to places decimal places (negative places round to tens, hundreds...) with mode, on x's 15 significant digits.
func Size ¶ added in v0.3.0
Size shows v bytes as nushell shows a file size: whole bytes below 1000 ("512 B"), and above that dec decimals of the largest unit, a thousand times apart, that keeps the number under 1000. Like nushell, it cuts the digits past dec rather than rounding them, so 2998 bytes is "2.9 kB", never a unit it hasn't reached. Negative sizes show a minus sign.
func SplitSerial ¶
SplitSerial returns the date and time parts of a serial, rounded to the second.
func TimeSerial ¶
TimeSerial is the fraction of a day for a time of day.