admin管理员组文章数量:1420973
I have script I am using here: /
It's supposed to change the background color of each individual table depending on the variable value. However, it does not work as it is now because the variables have a decimal and % after them. How can I make it only read the first two digits before the decimal, without changing what is displayed on the page. One thing to note is that on my site those are variables displayed, not static numbers.
I have script I am using here: http://jsfiddle/6b2yy/1/
It's supposed to change the background color of each individual table depending on the variable value. However, it does not work as it is now because the variables have a decimal and % after them. How can I make it only read the first two digits before the decimal, without changing what is displayed on the page. One thing to note is that on my site those are variables displayed, not static numbers.
Share Improve this question asked Sep 6, 2012 at 3:10 Jerry VirgoJerry Virgo 191 silver badge4 bronze badges2 Answers
Reset to default 5Use the parseInt function
parseInt('75.9%',10)
> 75
I guess in your case it would be
score = parseInt($(this).text(), 10);
Demo
Instead of reading the numbers up to the decimal, why not read and round the value properly?
parseInt('75.9%',10); //-> 75
Math.round(parseFloat('75.9%')); //-> 76
本文标签: parsingHow to only read digits before decimal in javascriptStack Overflow
版权声明:本文标题:parsing - How to only read digits before decimal in javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745339213a2654182.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论