float number和parseFloat的乘法返回NaN

时间:2014-08-16 04:20:06

标签: javascript jquery

我想获得当前计数的0.6,然后显示Math.float。但是NaN被退回了

$('.unemployed.count').html((Math.floor(parseFloat('0.6')*parseFloat($($('.unemployed.count').text())))).toString(10)); 

Html看起来像这样

   <div id='population'>
        <table id='population_data'>
            <tr tooltip='Unemployed  citizens'>
                <td>Unemployed</td>
                <td class='unemployed count'>2</td>
            </tr>
            <tr tooltip='Employed  citizens'>
                <td>Employed</td>
                <td class='employed count'>2</td>
            </tr>
        </table>
   </div>

我做错了什么? 感谢

2 个答案:

答案 0 :(得分:0)

问题在于此

parseFloat($($('.unemployed.count').text()))

http://jsfiddle.net/5v4pfxmk/

答案 1 :(得分:0)

试试这个:

$('.unemployed.count').html((Math.floor(parseFloat('0.6')*parseFloat(
$('.unemployed.count').text()))) // problem is in this line
.toString(10));

而不是

$('.unemployed.count').html((Math.floor(parseFloat('0.6')*parseFloat(
$($('.unemployed.count').text()))))
.toString(10));

<强> DEMO