为什么我的toFixed()函数不起作用? [英] Why is my toFixed() function not working?
本文介绍了为什么我的toFixed()函数不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是相关的代码.我已通过警报确认保存了正确的数字,只是没有将其更改为小数点后2位.
Here's the relevant code. I've confirmed with the alert that the correct number is saved, it's just not being changed to 2 decimal places.
if ($(this).attr('name') == 'time') {
var value = $(this).val();
parseFloat(value).toFixed(2);
alert(value);
editEntry.time = value;
}
推荐答案
您没有将解析的float分配回值var:
You're not assigning the parsed float back to your value var:
value = parseFloat(value).toFixed(2);
应该解决问题.
这篇关于为什么我的toFixed()函数不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文