javascript jQuery:将一个数字乘以 7.5
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4715780/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery: Multiply a number with 7.5
提问by curly_brackets
I'm about to design a webshop, build upon the Big Cartel webshop system. The nearest currency they use is Euro, but I want Danish Kroner (DKK), which is 7.5 of Euro.
我即将设计一个网上商店,建立在大卡特尔网上商店系统的基础上。他们使用的最接近的货币是欧元,但我想要丹麦克朗 (DKK),即 7.5 欧元。
How can I multiply the number within a div.price?
如何乘以 div.price 中的数字?
I've found "jQuery Calculate"-plugin, but I can't figure out how it works.
我找到了“jQuery 计算”插件,但我不知道它是如何工作的。
Plugin site: http://www.pengoworks.com/workshop/jquery/calculation/calculation.plugin.htm
插件站点:http: //www.pengoworks.com/workshop/jquery/calculation/calculation.plugin.htm
Thank you in advance...
先感谢您...
回答by ?ime Vidas
$('div.price').text(function(i,v) {
return Math.round(parseInt(v * 100, 10) * 7.5) / 100;
});
Live demo:http://jsfiddle.net/tbL5r/
现场演示:http ://jsfiddle.net/tbL5r/
回答by GoatInTheMachine
$("div.price").each(function(){
$(this).text(parseFloat($(this).text()) * 7.5);
});
But you really shouldn't be doing that with javascript.
但是你真的不应该用javascript来做。

