开发者

Chrome problem parsing Float from jquery css atribute

开发者 https://www.devze.com 2023-01-19 07:59 出处:网络
today i have a simple an understable problem for me . Next code: alphavar = $(\'#frontcolour\').css(\'opacity\');

today i have a simple an understable problem for me . Next code:

alphavar = $('#frontcolour').css('opacity');
console.debug(alphavar+' '+parseFloat(alphavar));

It runs ok width Firefox and width Opera ( now all perfect :) ) , but chrome i dont know why it doesnt parse it ok : here the answer of the 开发者_JAVA技巧debug send for me (the second line of the code)

0,568966 0

The real value is 0.568966 , but chrome it seems to round it also being parseFloat not parseInt. Any idea?

Thx in advance .


The string has a comma instead of a period: "0,568966" instead of "0.568966". Perhaps Firefox and Opera adjust the workings of parseFloat to deal with locale variation, but apparently Chrome does not.


use .tofixed() this function will return the number of digits are required after decimal points. Below example work for me in the Chrom and the Mozila as well

$("#total_amount").val(parseFloat($amt * $ticket).toFixed(2));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号