我的代码:十进制数越来越即消失
var $label = $(ev.currentTarget);
var $price = $label.parent("form").find(".oe_price .oe_currency_value");
if (!$price.data("price")) {
$price.data("price", parseFloat($price.text()); //price is 10.30 but it returns 10.3 as number
}
$price.html($price.data("price")+parseFloat($label.find(".badge span").text() || 0));
/* The value coming in **badge** is **12.00**
* but parseFloat converts that into **12**
* thats why after the addition I got the output as **22.3**
* but i want it as **22.30**
*/
我有一个字符串
'10 0.30'
现在,如果我转换使用parsefloat
字符串到数字parseFloat('10.30')
我得到的输出10.3
,如果我是用.tofixed(2)
parseFloat('10 0.30' )做的。toFixed(2)
我得到了输出10.30但它在STRING这对我来说是个大问题,因为我想输出为号码。
如果我不喜欢这样
数(parseFloat('10 0.30' )。toFixed(2))
我得到的输出10.3
但我想在输出数和小数点 这样10.30
PLZ帮助... !!!
数字'10.3'与'10.30'完全相同,所以为什么它在数字上很重要?如果是在网页中呈现,那么字符串就可以了。 –
最后一位数字是0,与浮点计算无关,因此将其包含在内。当你输出某些东西时,它会变成一个字符串,那么究竟是什么问题呢? – gpgekko
请检查http://stackoverflow.com/questions/2221167/javascript-formatting-a-rounded-number-to-n-decimals/2909252#2909252 –