Youss
Youss

Reputation: 4222

get complete number

I have a script which allows to display search results. Given a query there is a function which is called 'webresultTotal' and it gives me a nuber like'544' With this number I want to do a pagination, so I have li like this <li class="page"></li>

So given the number by webResultTotal I want to show/hide the set of li. But Im having trouble when the number is below 900:

if (webResultTotal < 900)
        {
          $('.page:lt('+Math.min(webResultTotal/10)+')').show();
        }

If the webResultTotal is '544' no li is visible. I think the problem is that '544/10=54,4' Which is not a whole number, so nothing hapens. How can I change the code so that it doesnt get '54,4' but instead a complete number like '54'

Upvotes: 0

Views: 73

Answers (2)

Marc
Marc

Reputation: 6771

Use Math.ceil() or Math.floor().

Upvotes: 1

Rene Pot
Rene Pot

Reputation: 24815

You probably want to round it up, so you'll get a 55th page.

You can do this with JavaScript Math.

Math.ceil(54.4); // returns 55
Math.round(54.4); // returns 54

You might also like the floor() method

Math.floor(54.9); // returns 54

Take a look at the Math docs: http://www.w3schools.com/jsref/jsref_obj_math.asp

Upvotes: 3

Related Questions