-1

I need to get a next value if the current value has decimal point(.1 to .9. not .0) with JavaScript.

Lets say:

var allRecords = 214;
var totalRecordSinglePage = 10;
var totalPages = (allRecords / totalRecordSinglePage)

Now the value of

totalPages = 21.4

But I want to convert 21.4 into 22.

So new value of

totalPages = 22

How can I do this in JavaScript?

cweiske
  • 30,033
  • 14
  • 133
  • 194
asax
  • 237
  • 6
  • 21

4 Answers4

2

I believe you're looking for the ceiling function: Math.ceil(totalPages);

More detail here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil

Paul
  • 402
  • 4
  • 12
1

Math.ceil() is the function you need.

var totalPages = Math.ceil(allRecords / totalRecordSinglePage);
Paritosh
  • 11,144
  • 5
  • 56
  • 74
1

Use Math.ceil(x), where x is the number.

kingshuk basak
  • 423
  • 2
  • 8
0

Math.ceil does exactly that.

Math.ceil(allRecords / totalRecordSinglePage)
jonathanGB
  • 1,500
  • 2
  • 16
  • 28