Quote:
Originally Posted by nittwitt103
Hello! Yes, you are 100% correct. Those are already built in, but I'm using a form of VDP software that has it's own unique "building blocks". For instance I tried using "parseInt" to no avail in another area (though I may have been guilty of doing it wrong). It's doubly hard because I'm learning JS and having to learn this as well.
You help is much appreciated though!
|
if javascript logic works correctly, there are low-level computer-science substitutions you can use.
if you don't need it to be an integer strictly speaking but just a number that will add instead of concat, you can use either
Code:
val="123";
(val *1) === Number( val ) // times one
or
Code:
val="123";
+val === Number( val ) // leading plus
those are harder to read than Number(), Math.floor(), parseFloat() and ParseInt(), but they add up.
for integers, you can do other ones to floor or round:
Code:
var num=Math.random();
parseInt( num * 10 ) === (0| num * 10) ;
aka:
Code:
var num=Math.random();
Math.floor( num * 10 ) === (0| num * 10) ;
as a callable function:
Code:
function int(number){ return 0|number;}
if your numbers are known to be positive and you want to round it instead of floor it,
Code:
val ="123.876";
+val+.5|0
if the numbers are negative, you have to flip the sign, round it and unflip...