Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 14 days ago.
Improve this question
I need to convert values of type int32 to float values
I have the value of 39900 and I need to convert to 399.00, or 7400 to convert to 74.00 or 4378 to 43.78, they are not fixed values.
You just need to divide the number by 100, this will put the last 2 digits in the fractions. You don't need to worry about integer and float weirdness from C-like languages, since in Javascript, all numbers are floats, as #pilchard has pointed out.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I need to tokenize a string representing an item in inventory in javascript getting words and numbers, for example:
Given the string 'Plane Engine 50x60' the tokens should be ['Plane','Engine','50','x','60']
Given the string 'Car wheel 220v' the tokens should be ['Car','wheel','220','v']
The solution could be a RegExp or a Javascript Algorithm
All the items have that kind of names come has measures like 20x30 and others have electronic info such as 220v. The thing I need to do is split like the examples above.
Thanks
We can split by groups of either numbers or letters and then filter out the empty strings or spaces.
'Car wheel 220v'.split(/([0-9]+|[a-zA-Z]+)/).filter(token => (token.match(/[a-zA-Z0-9]/)))
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
How to convert string to valid json ?
const string = "[{foo:bar,key:value},{foo:bar,key:value}]";
So that i can parse it using JSON.parse(string).
Note that : i cant manually put (") to every keys and values. I am stack here that's why i am on stackoverflow.
Using regex to replace any words or numbers will work for the json you have supplied, it will not however work if you have mixed value and "value" properties.
var text = "[{foo:bar,key:value},{foo:bar,key:value}]";
console.log(JSON.parse(text.replace(/(\w+|\d+)+/g, '"$1"')));
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
My goal is to pull chunks of 0's or 1's from a binary string. Using regex.match to look for patterns pulls out all chunks and loses order. I need to be able to pass any length of binary to it. How can I correctly pull out chunks so that '10011000001' -> '1', '00', '11', '00000', '1'?
I can only think to run a loop to count the number of changes from 0 to 1 then run alternating regex.match() on it, but that's certainly inefficient.
You could look for a digit and look for more of the same group.
var string = '10011000001',
parts = string.match(/([01])\1*/g);
console.log(parts);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I need to create a function that gets a number and return a float (not as string), how can I do it?
Function (num) {
return num.toFloat()
}
JavaScript only has a single number type. Every number is already a floating point value, following the IEEE 754 standard.
There is nothing you have to do.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I've always wondered how on earth does Javascript picks a random number and how can it possibly be random? Don’t computers just take in some input, swirl it around with some math, and then return it?
I'm not asking how to generate a random number with Math.random(), my question is: What happens when you want to generate a ‘random’ number? How does that even work and what’s happening behind the scenes? I understand it's a big topic to discuss but any links will be appreciated!
Some random number generator functions use some kind of system noise or entropy (eg: current timestamp) and apply some mathematical function to it to generate random numbers. They are "true" random numbers.
Some functions work by using a seed value and an algorithm to generate numbers that appear to be random, but that is in fact predictable. They are called "Pseudorandom" numbers.
You can read more here: https://www.howtogeek.com/183051/htg-explains-how-computers-generate-random-numbers/