mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-22 16:23:50 +00:00
fix in calculating page fun
This commit is contained in:
parent
e78961b597
commit
8461ff4d38
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user