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 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 Fixed(x float64, n int, mode Rounding) (whole, frac string)
- func Format(v float64, pat string) string
- func General(v float64) string
- func GeneralFit(v float64, width int) string
- func Round(x float64, places int, mode Rounding) float64
- func SerialOf(t time.Time) float64
- 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 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 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 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 Round ¶
Round rounds x to places decimal places (negative places round to tens, hundreds...) with mode, on x's 15 significant digits.
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.