diff --git a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/Pagination.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/Pagination.kt index 0bd7a87ace3..53d8958dc42 100644 --- a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/Pagination.kt +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/Pagination.kt @@ -1,6 +1,7 @@ package dev.inmo.micro_utils.pagination import kotlin.math.ceil +import kotlin.math.floor /** * Base interface of pagination @@ -54,4 +55,8 @@ fun calculatePagesNumber(datasetSize: Int, pageSize: Int): Int = /** * @return calculated page number which can be correctly used in [PaginationResult] as [PaginationResult.page] value */ -fun calculatePage(firstIndex: Int, resultsSize: Int): Int = firstIndex / resultsSize +fun calculatePage(firstIndex: Int, resultsSize: Int): Int = if (resultsSize > 0) { + floor(firstIndex.toFloat() / resultsSize).toInt() +} else { + 0 +}