Skip to content

TotalPages no valid #2

@sergiocauich

Description

@sergiocauich

The number of pages is not valid when the totalRecords / perPageInt is a whole number
since it always increases by 1

I propose this solution:

func getTotalPages(perPage string, totalRecords int) int64 {
	perPageInt, _ := strconv.ParseInt(perPage, 10, 32)
	totalPages := float64(totalRecords) / float64(perPageInt)
	
	b := (totalPages - float64(int64(totalPages)))
	
	if b <= 0 {
		return int64(float64(totalPages))
	}
	// This stupid conversion is needed as golang does not have any round method.
	// Chance for creating a new library ??
	return int64(float64(totalPages) + float64(1.0))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions