Skip to content

Tag: math

check if number string contains decimal?

After doing a sqrt() How can I be check to see if the result contains only whole numbers or not? I was thinking Regex to check for a decimal – if it contains a decimal, that means it didn’t root evenly into whole numbers. Which would be enough info for me. but this code isnt working… I bet t…

Make a number a percentage

What’s the best way to strip the “0.”XXX% off a number and make it a percentage? What happens if the number happens to be an int? Answer A percentage is just: No need for anything fancy:

JavaScript Number Split into individual digits

I am trying to solve a math problem where I take a number e.g. 45, or 111 and then split the number into separate digits e.g. 4 5 or 1 1 1. I will then save each number to a var to run a method on. Does anyone know how to split a number into individual digitals? For example I

Write a truly inclusive random method for javascript

Javascript’s MATH object has a random method that returns from the set [0,1) 0 inclusive, 1 exclusive. Is there a way to return a truly random method that includes 1. e.g. While this always returns a number from the set [0,1] it is not truly random. Answer To put it bluntly, what you’re trying to …