1

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 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 .

A.Quiroga
  • 5,704
  • 6
  • 37
  • 58

2 Answers2

3

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.

Pointy
  • 405,095
  • 59
  • 585
  • 614
0

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));
Nikunj K.
  • 8,779
  • 4
  • 43
  • 53