Javascript jquery与断号乘法
我使用jquery对价格*数量函数进行了编码,但没有响应每日价格。它们是十进制数 这是代码Javascript jquery与断号乘法,javascript,decimal,multiplication,Javascript,Decimal,Multiplication,我使用jquery对价格*数量函数进行了编码,但没有响应每日价格。它们是十进制数 这是代码 var qty = "3"; var price = "1.20"; var res = (qty*price); $("#boxres").html(res); 结果是3.599999996 我只想要3.6分 我怎样才能修好它?用便士存储东西: var qty = 3; var cost = 120; var res = cost * qty; var res_str = '£'+Math.f
var qty = "3";
var price = "1.20";
var res = (qty*price);
$("#boxres").html(res);
结果是3.599999996
我只想要3.6分
我怎样才能修好它?用便士存储东西:
var qty = 3;
var cost = 120;
var res = cost * qty;
var res_str = '£'+Math.floor(res / 100)+'.'+(res %100).toFixed(2);
用便士储存物品:
var qty = 3;
var cost = 120;
var res = cost * qty;
var res_str = '£'+Math.floor(res / 100)+'.'+(res %100).toFixed(2);
用便士储存物品:
var qty = 3;
var cost = 120;
var res = cost * qty;
var res_str = '£'+Math.floor(res / 100)+'.'+(res %100).toFixed(2);
用便士储存物品:
var qty = 3;
var cost = 120;
var res = cost * qty;
var res_str = '£'+Math.floor(res / 100)+'.'+(res %100).toFixed(2);
使用Math.round
var res = (Math.round((qty*price)*10)/10).toFixed(2);
编辑以强制到第100个。谢谢dave。使用Math.round
var res = (Math.round((qty*price)*10)/10).toFixed(2);
编辑以强制到第100个。谢谢dave。使用Math.round
var res = (Math.round((qty*price)*10)/10).toFixed(2);
编辑以强制到第100个。谢谢dave。使用Math.round
var res = (Math.round((qty*price)*10)/10).toFixed(2);
编辑以强制到第100个。谢谢戴夫。试试看
$("#boxres").html(res.toFixed(1));
试试看
$("#boxres").html(res.toFixed(1));
试试看
$("#boxres").html(res.toFixed(1));
试试看
$("#boxres").html(res.toFixed(1));
可能重复的“否”这是不同但相同的基数。您是否尝试对数字进行四舍五入?另外,代码中唯一的jQuery是最后一行,与您的实际问题或答案无关。哈哈,我用toFixed(1)解决了问题,但是舍入没有解决我的问题可能是重复的否这是不同的,但相同的基数您是否尝试舍入数字?另外,代码中唯一的jQuery是最后一行,与您的实际问题或答案无关。哈哈,我用toFixed(1)解决了问题,但是舍入没有解决我的问题可能是重复的否这是不同的,但相同的基数您是否尝试舍入数字?另外,代码中唯一的jQuery是最后一行,与您的实际问题或答案无关。哈哈,我用toFixed(1)解决了问题,但是舍入没有解决我的问题可能是重复的否这是不同的,但相同的基数您是否尝试舍入数字?另外,代码中唯一的jQuery是最后一行,与实际问题或答案无关。哈哈,我用toFixed(1)解决了问题,但round不能解决我的问题