Jquery 输出到小数点后2位
我试图将以下内容输出到小数点后2位:Jquery 输出到小数点后2位,jquery,Jquery,我试图将以下内容输出到小数点后2位: $("#incP1").click(function(){ $(":text[name='qty1']").val( Number($(":text[name='qty1']").val()) + 1 ); $(":text[name='cost1']").val( Number($(":text[name='cost1']").val()) + 1.99 ) ; }); 我一直在尝试使用toFixed2,但运气不好。任何建议都很好。这应该有用:
$("#incP1").click(function(){
$(":text[name='qty1']").val( Number($(":text[name='qty1']").val()) + 1 );
$(":text[name='cost1']").val( Number($(":text[name='cost1']").val()) + 1.99 ) ;
});
我一直在尝试使用toFixed2,但运气不好。任何建议都很好。这应该有用:
$(":text[name='qty1']").val( (+$(":text[name='qty1']").val() + 1).toFixed(2) );
js中的1+1=11。您需要先使用parseInt或parseFloat。@Tommi抱歉,忘记了a+Ahh非常好,非常感谢。