Reputation: 1780
I have strings of numbers...
**[0.7955635, 485, .421, 1.08]**
Assuming i have a jquery selector for this collection, how would I format them to always show a leading zero (or integer) followed by two decimal places: [0.79, 485.00, 0.42, 1.08].
Upvotes: 0
Views: 2868
Reputation: 52769
Example -
var data = [0.7955635, 485, .421, 1.08];
$(data).each(function(index, value){
alert(parseFloat(value).toFixed(2));
})
Demo - http://jsfiddle.net/vnW7H/
Upvotes: 2