sort.go
func (s *SortFilter) Num(n int) *SortFilter {
	s.add(func(a, b string) int {
		a1, a2 := column(a, n)
		b1, b2 := column(b, n)
		switch {
		case a1 < b1:
			return -1
		case a1 > b1:
			return +1
		}

		// Convert columns from strings to numbers.
		a3, a4 := strconv.ParseFloat(a2, 64)
		b3, b4 := strconv.ParseFloat(b2, 64)

		if a4 != b4 {
			// Errors sort after numbers.
			if a4 != nil { // a had a parse error, b did not
				return +1
			}
			// b had a parse error, a did not
			return -1
		}

		switch {
		case a3 < b3:
			return -1
		case a3 > b3:
			return +1
		}
		return 0
	})
	return s
}
func (s *SortFilter) Num(n int) *SortFilter {
	s.add(func(a, b string) int {
		a1, a2 := column(a, n)
		b1, b2 := column(b, n)
		switch {
		case a1 < b1:
			return -1
		case a1 > b1:
			return +1
		}

		// Convert columns from strings to numbers.
		a3, a4 := strconv.ParseFloat(a2, 64)
		b3, b4 := strconv.ParseFloat(b2, 64)

		if a4 != b4 {
			// Errors sort after numbers.
			if a4 != nil { // a had a parse error, b did not
				return +1
			}
			// b had a parse error, a did not
			return -1
		}

		switch {
		case a3 < b3:
			return -1
		case a3 > b3:
			return +1
		}
		return 0
	})
	return s
}
func ( s * SortFilter ) Num ( n int ) * SortFilter { s . add ( func ( a , b string ) int { a1 , a2 := column ( a , n ) b1 , b2 := column ( b , n ) switch { case a1 < b1 : return - 1 case a1 > b1 : return + 1 } // Convert columns from strings to numbers. a3 , a4 := strconv . ParseFloat ( a2 , 64 ) b3 , b4 := strconv . ParseFloat ( b2 , 64 ) if a4 != b4 { // Errors sort after numbers. if a4 != nil { // a had a parse error, b did not return + 1 } // b had a parse error, a did not return - 1 } switch { case a3 < b3 : return - 1 case a3 > b3 : return + 1 } return 0 } ) return s }
// Num sets the next sort key to sort by column n in numeric
// order. Column 0 means the entire string. Items that do not have
// column n sort to the front.  Items whose column n is not a number
// sort to the end.
Num sets the next sort key to sort by column n in numeric order . Column 0 means the entire string . Items that do not have column n sort to the front . Items whose column n is not a number sort to the end .