This question already has answers here:
console.log of element.children shows 0 length but has three entries when expanded later
(1 answer)
console.log() async or sync?
(3 answers)
Closed 5 years ago.
I have an array angles which contains five arrays, each of which contain two numbers.
console.log(angles) reports angles[0] to be [1.5707963267948966, 0.7853981633974483]. Natural conclusion is that I made a mistake in my math somewhere.
console.log(angles[0]) reports the same values as above. However, console.log([angles[0][0],angles[0][1]]) reports [1, 0.5], which is the expected result.
Notably, console.log(angles[0]) reports the erroneous numbers in the expanded result, but the preview displays the correct values.
Issue is not present for angles[n] where n is not 0.
What's happening here? Is there an error in console.log?
Related
This question already has answers here:
Check array in JS - is list sorted? [duplicate]
(9 answers)
Check if an array is descending, ascending or not sorted?
(10 answers)
Closed 1 year ago.
How can I check if an array of numbers e.g
const number = ['15','14','11','5'] is sorted from high to low in js
note: array could also be in invalid order
This question already has answers here:
How to deal with floating point number precision in JavaScript?
(47 answers)
Dealing with float precision in Javascript [duplicate]
(5 answers)
Closed 5 years ago.
I just want for example multiply 7.50*1.19
Iam pretty sure it´s 8,925 but if i calculate it in my js i get 8.924999999999999 and i cannot get a correct rounding to finally get 8,93
parseFloat(tarif.field_grundpreis * 1.19)
Result = 8.924999999999999
While tarif.field_grundpreis is 7.50
It´s crazy, please help.
This question already has answers here:
Large numbers erroneously rounded in JavaScript
(6 answers)
Closed 7 years ago.
I was goofing around when I decided to try to show a varaible on the console. this is my JS
test = 8888888888888888888;
console.log(test)
however, on the console, this was shown:
Why did 8888888888888888888 go to 8888888888888889000?
The number is larger than the largest value that can be represented exactly in a double-precision floating point value. Modern runtimes expose a constant on the Number constructor with the maximum value (Number.MAX_SAFE_INTEGER). The value is 9007199254740991.
This question already has answers here:
Is floating point math broken?
(31 answers)
Closed 7 years ago.
Why the result of this data is doesn't give the exact value expected by a human brain or expected output of a person to appear
16.08 * 100 = 1607.9999999999998;
When i tried it to the console developer of the chrome browser;
and i tried using
console.log(16.08*100); gives 1607.9999999999998
Supposedly the answer that i should be seeing is
16.08 * 100 = 1608;
will you please help me with these. or any explanations
use .toFixed(n) method of javascript.
console.log((16.08 * 100).toFixed());
This question already has answers here:
How to easily truncate an array with JavaScript?
(7 answers)
Closed 9 years ago.
Let's say I'm working with an array that has a bunch of items, always over 20, but never the same amount. I want to trim that array to just 10 items. The answer here doesn't take into account varying sized arrays.
What's a good way to do this?
You can slice an array with Array.slice() :
new_array = old_array.slice(0,10);
FIDDLE
This trims the array in place:
arr.length = 10;