1

I want to convert a string to double then store it into array of type double at the last, I did the following:

var num = "";
var sym = new Float64Array();

sym[sym.length] = parseFloat(num);

but when I prints the array I get undefined , so where is the wrong I did ?

3 Answers 3

2

Make necessary modfications. Refer Float64Array API .You define length in Float64array as a parameter.

your length is coming 1.

var num = "65";
var x = new Float64Array(1);
x[x.length-1] = parseFloat(num);
console.log(x[0]);
Sign up to request clarification or add additional context in comments.

9 Comments

I got the value 0 stored into x[0] while the num value is 65
dint get you, can you please share the code. what you did on your side.
you can also make use of set method. var num = "65"; var x = new Float64Array(2); x[0] = 0; x.set([65],x.length-1) console.log(x[1]);
Can you modfiy that fiddle a little bit and update your comment.
thank you very much, the error was in the function expression() , now its working fine
|
1

Float64Arrays can't grow and shrink like ordinary JS arrays. You have to allocate all the elements when creating it:

var sym = new Float64Array(10);

You can then assign elements:

sym[0] = 123.456;
console.log(sym);
> [123.456, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Comments

-1
var arr = [];
var num = parseFloat("123.123")
arr.push(num);
console.log(arr);

1 Comment

You're not using Float64Array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.