kinet
kinet

Reputation: 1780

format decimals javascript/jquery

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

Answers (1)

Jayendra
Jayendra

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

Related Questions