Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
Passcode:
How to convert integer number from float in jquery
4002 Views
Note 
For this three math functions are available.According to your need use the function.
  1. Math.ceil()
  2. Math.round()
  3. Math.floor()
Math.ceil() 
If the input float value is
1.1 or 1.2 or 1.5 or 1.8 i.e (1.1 to 1.9)

Output is
2
Math.round() 
If the input float value is
1.1 or 1.2 i.e (1.1 to 1.4)

Output is
1

If the input float value is
1.5 or 1.8 i.e (1.5 to 1.9)

Output is
2
Math.floor() 
If the input float value is
1.1 or 1.2 or 1.5 or 1.8 i.e (1.1 to 1.9)

Output is
1
Html
<div class="extra"></div>
Jquery
	$(function () {
	   var a = 7 / 5;
	   var n = Math.ceil(a);
	   $(".extra").append('<div>' + n + '</div>');
	   var m = Math.round(a);
	   $(".extra").append('<div>' + m + '</div>');
	   var o = Math.floor(a);
	   $(".extra").append('<div>' + o + '</div>');
	});
Demo 
Best Lessons of "JQuery Examples"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details