Reputation: 8717
I have an object:
var seriesOptions = {
y: parseFloat($(this).find('y').text()).toFixed(2),
color: colors[index],
level : dlevel
};
Where I am parsing and assigning value via reading a XML tree structure:
<series> <!-- $this--><y>55.34</y></series>
Below the code I make a copy of the object
series = $.extend(true, {}, seriesOptions);
The issue I am facing is that the "y" property gets converted from 55.34 to "55.34" (converted to string type) which makes my code behaving faulty. Is there a way I can copy seriesOptions.y to series.y as integer itself?
Upvotes: 0
Views: 152
Reputation: 51201
Since toFixed() returns a string
you could either say parseFloat()
afterwards or start with an operation that converts the string to number automatically.
Upvotes: 0
Reputation: 48793
You could use
Math.round(parseFloat($(this).find('y').text())*100)/100
Instead of
parseFloat($(this).find('y').text()).toFixed(2)
And your 'y'
will be number
, not string
.
Upvotes: 1