admin管理员组文章数量:1221773
Can you guys please help me in this matter :
I have two variable in jquery x and y , and I am doing a division between those two , and I let's say the result is 2.5 , but I only want to show 2 from 2.5 , how do I do that?
Can you guys please help me in this matter :
I have two variable in jquery x and y , and I am doing a division between those two , and I let's say the result is 2.5 , but I only want to show 2 from 2.5 , how do I do that?
Share Improve this question edited Jul 31, 2012 at 18:42 Colin Brock 21.6k9 gold badges49 silver badges62 bronze badges asked Jul 31, 2012 at 18:41 southpaw93southpaw93 1,9615 gold badges23 silver badges40 bronze badges 4- 1 What exactly are you trying to do? Truncate the decimal? Round down? Round up? Perhaps just use Math.Floor: var z = Math.Floor(x/y); – AceCorban Commented Jul 31, 2012 at 18:43
- 3 Somehow I'm reminded of this picture. – JJJ Commented Jul 31, 2012 at 18:43
- @Juhana my thoughts too. – SomeKittens Commented Jul 31, 2012 at 18:43
- $('jQuery').explosion(); – Mark Pieszak - Trilon.io Commented Jul 31, 2012 at 18:45
3 Answers
Reset to default 13If you're simply trying to truncate the decimal, use the following:
parseInt(2.5); // returns 2
If you're trying to round to the nearest integer, use the following:
Math.round(2.5); // returns 3
If you're trying to round down, use the following:
Math.floor(2.5); // returns 2
If you're trying to round up, use the following:
Math.ceil(2.5); // returns 3
Use simply parseInt() within javascript on the result
var x = 12.5;
var y = 5;
var result = parseInt(x / y, 10); // the 2nd parameter signifies base-10
alert(result);
You don't need to use jQuery at all for this. Simply use JavaScript's parseInt()
method.
本文标签: javascriptJquery division between two numbersStack Overflow
版权声明:本文标题:javascript - Jquery division between two numbers - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739330307a2158447.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论