javascript / beginner
Snippet
Rounding Numbers Down with Math.floor()
Math.floor() rounds a number down to the nearest integer. This is frequently used in Next.js applications for logic like pagination, where you need to calculate how many full pages of data are available.
snippet.js
1
2
3
4
function PaginationInfo(props) {const completePages = Math.floor(props.totalItems / props.pageSize);return <div>Full pages available: ' + completePages + '</div>;}
nextjs
Breakdown
1
Math.floor(...)
The math function that forces the result to be the largest integer less than or equal to the input.