# best of string to number conversion (v11)

## Description

all the conversions I can think of

## Setup

``var abc = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, '0.01', '0.02', '0.03', '0.04', '0.05', '0.06', '0.07', '0.08', '0.09', '0.10'];``

## Test runner

Testing in
TestOps/sec
Number()
``````var result = 0,
converted;
for (var i = 0, len = abc.length; i < len; ++i) {
converted = Number(abc[i]);
if (!isNaN(converted)) {
result += converted
}
}``````
parsetInt()
``````var result = 0,
converted;
for (var i = 0, len = abc.length; i < len; ++i) {
converted = parseInt(abc[i], 10);
if (!isNaN(converted)) {
result += converted
}
}``````
parseFloat()
``````var result = 0,
converted;
for (var i = 0, len = abc.length; i < len; ++i) {
converted = parseFloat(abc[i]);
if (!isNaN(converted)) {
result += converted
}
}``````
implicit
``````var result = 0,
converted;
for (var i = 0, len = abc.length; i < len; ++i) {
converted = +abc[i];
if (!isNaN(converted)) {
result += converted
}
}``````
minus 0 hack
``````var result = 0,
converted;
for (var i = 0, len = abc.length; i < len; ++i) {
converted = abc[i]-0;
if (!isNaN(converted)) {
result += converted
}
}``````
0| hack
``````var result = 0,
converted;
for (var i = 0, len = abc.length; i < len; ++i) {
converted = 0|abc[i];
if (!isNaN(converted)) {
result += converted
}
}``````
valueOf()
``````var result = 0,
converted;
for (var i = 0, len = abc.length; i < len; ++i) {
converted = abc[i].valueOf();
if (!isNaN(converted)) {
result += converted
}
}``````
>>0
``````var result = 0,
converted;
for (var i = 0, len = abc.length; i < len; ++i) {
converted = abc[i] >> 0;
if (!isNaN(converted)) {
result += converted
}
}``````
Math.floor()
``````var result = 0,
converted;
for (var i = 0, len = abc.length; i < len; ++i) {
converted = Math.floor(abc[i]);
if (!isNaN(converted)) {
result += converted
}
}``````
Math.round()
``````var result = 0,
converted;
for (var i = 0, len = abc.length; i < len; ++i) {
converted = Math.round(abc[i]);
if (!isNaN(converted)) {
result += converted
}
}``````
~~
``````var result = 0,
converted;
for (var i = 0, len = abc.length; i < len; ++i) {
converted = ~~abc[i];
if (!isNaN(converted)) {
result += converted
}
}``````
>>>0
``````var result = 0,
converted;
for (var i = 0, len = abc.length; i < len; ++i) {
converted = abc[i] >>> 0;
if (!isNaN(converted)) {
result += converted
}
}``````
/1
``````var result = 0,
converted;
for (var i = 0, len = abc.length; i < len; ++i) {
converted = abc[i]/1;
if (!isNaN(converted)) {
result += converted
}
}``````
0+
``````var result = 0,
converted;
for (var i = 0, len = abc.length; i < len; ++i) {
converted = 0+abc[i];
if (!isNaN(converted)) {
result += converted
}
}``````
+0
``````var result = 0,
converted;
for (var i = 0, len = abc.length; i < len; ++i) {
converted = abc[i]+0;
if (!isNaN(converted)) {
result += converted
}
}``````

## Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.