converting string to float/number for numerical operations in javascript

murraycattle

New Member
I'm having some issues converting a string to a number for numerical calculations in javascript/knockoutI have the following to calculate the total cost of an order in a knockout form\[code\]self.totalCost = ko.computed(function() { var total = 0; for (var i = 0; i < self.itemNumbers().length; i++) //somehow convert the price to a number here so then I can add it total += self.itemNumbers().item.price; return total;});\[/code\]The display shows nothing, however, when I change "return total" to "return i" the total then displays. I'm assuming means the prices are strings and can't be added. When I output the prices in a table they show up as a decimal (such as 19.99) but I'm not sure if they're actually numbers or strings.
 
Top