FAQ Database Discussion Community


Checking if variable is an Integer in Javascript

javascript,parseint
I'm starting to learn JavaScript at school and one of the assignments require me to check user's input whether it is an Integer or not. This code DOES NOT WORK FOR ME ON CHROME. var person = prompt("Please enter your name", "Enter Name"); alert("Hello " + person); var age =...

Strange behaviour with spliting a string in Javascript

javascript,internet-explorer-11,parseint
I am trying to do something relatively simple. I have a date in this format dd/MM/yyyy eg: var newDate = "‎11‎/‎06‎/‎2015"; And I want to convert it to a date. This code only works in Chrome and Firefox: new Date(newDate) In IE11 I get Nan So I am trying to...

parseInt() not working as expected

jquery,parseint
I am custom coding an image slider right now and I am adding a data-slideNum attribute to each slider image and thumbnail image like so: $('.slide').each(function(i) { $(this).attr('data-slideNum',i); }); $('.thumbnail').each(function(i) { $(this).attr('data-slideNum',i); }); Of course this numbers the slides 0-X. Below the slider I would like to put a caption...

NaN being returned on parseInt() [closed]

javascript,jquery,parseint
http://jsfiddle.net/leongaban/fhhmLfab/ In the example above I have 3 buttons, orange, green and red. On hover each reveals a [ - ] and a [ + ] button with a class of btn_action. On click I'm trying to grab the numerical value from the target color button and then increment or...

Cannot Find Symbol Error with event handler

java,if-statement,scope,initialization,parseint
I am having trouble trying to initialize a variable correctly. Earlier I was getting a Number Format Exception because I was parsing an integer inside of an empty text field. Now I have created an if statement that checks first to see if the field is empty, then parses an...

No conversion with Integer.ParseInt()

java,data-conversion,parseint
I have a problem that when I use Integer.parseInt in this context it doesn't convert my and somehow it even kick me out of loop so it dont't want to display for example System.out.print(1) after loop like everything was crashed but i have no error. Please help. That's a part...

How can i pass all integers i this loop and stop before the last line

java,linked-list,bufferedreader,stringtokenizer,parseint
this is my input first line 5 6 3 4 2 3 2 5 1 0 word 2 2 4 i need to add all the integers to a graph but not the last line (word 1 2 4).. i have splitted the first line (first line etc.) and put...

Android convert milliseconds to hours

java,android,time,calendar,parseint
I have milliseconds in String and i want to get hour and minutes from it. This is my code: String ms = "1425652847915"; int t = Integer.parseInt(ms); Calendar c = Calendar.getInstance(); c.set(Calendar.MILLISECOND, t); int h = c.get(Calendar.HOUR_OF_DAY); int m = c.get(Calendar.MINUTE); But i got this error: java.lang.NumberFormatException: unable to parse...

parseInt not working with data from an Array created from a spitted Date inside Angularjs controller [duplicate]

javascript,angularjs,parseint
This question already has an answer here: ToLocaleDateString() changes in IE11 4 answers I have a date that I am converting to LocaleDateString and then splitting it into an array inside an angulrajs controller. When I try to convert to int the elements in the array I get NaN....

Java issue using parseInt with a try catch block

java,try-catch,parseint
I am working on an exercise, where I have to select a category(genre) of movie and based on my selection, the program will return a list of movies in that category from an ArrayList of objects. My program works when typing out a category in string format. However I am...

Why does parsing a large number, of string form, give a larger number? [duplicate]

javascript,parseint
This question already has an answer here: Why do JavaScript converts some number values automatically 4 answers See snippet: var num = "9223372036854775808"; document.write(num); document.write("<br>"); document.write(parseInt(num, 10)); On running the code snippet, the first write yields: 9223372036854775808 and the third write yields: 9223372036854776000 But, I am only parsing the...

Android Java - NumberFormatException while parsing “76”

java,android,zlib,numberformatexception,parseint
I'm working on an Android app using zbar to decode QR. The structure of the QR is: "SpecificPrefix/[Number]". String d = sym.getData(); // I get the QR text from the symbol if(d.startsWith(QRUri)) { // QRUri is a string const containig the prefix int id; try { Log.d("NOT", "QR Subst \""...

JavaScript Bitwise Masking

javascript,node.js,bit-manipulation,tostring,parseint
This question is similar to this other question; however, I'd like to understand why this is working as it is. The following code: console.log((parseInt('0xdeadbeef', 16) & parseInt('0x000000ff', 16)).toString(16)); console.log((parseInt('0xdeadbeef', 16) & parseInt('0x0000ff00', 16)).toString(16)); console.log((parseInt('0xdeadbeef', 16) & parseInt('0x00ff0000', 16)).toString(16)); console.log((parseInt('0xdeadbeef', 16) & parseInt('0xff000000', 16)).toString(16)); console.log((parseInt('0xdeadbeef', 16) &...

PHP parse int wrong in XAMPP windows

php,windows,xampp,parseint
demo $code = '40001042901'; echo (int)$code; //intval($code) //same I test on linux (Ubuntu) that result is 40001042901 but on windows result is 2147483647, what wrong with that? XAMPP 1.8.3, PHP 5.5.15, Apache 2.4.10 (Win32)...

Converting request.getParameterValues() to int array

java,arrays,jsp,parseint
I tried looking for help on the web to solve my problem but to no avail. I wish to convert verify[] to int, so it can be processed in the query. verified column has a data type of string staff_id column has a data type of autonumber I'm getting an...

I cannot obtain numerical values from input elements, even using parseInt

javascript,input,parseint
I am making a speed calculator where you enter the numbers and you get a speed. here is the code... <html> <head><title>speed</title></head> <body> <font face="arial"> <h1>Speed Calculator</h1> <form> distance: <input type="text" size="3" id="distance"> </form> time: <input type="text" size="3" id="hours"> Hours <pre> <pre> <input type="button" value="Speed" id="button"> <script> var dist =...

Getting returned “[object Object] NaN” - Javascript

javascript,canvas,nan,parseint
As the title says, when i execute my code, in the console i get returned "[object Object] NaN" (with quote marks in console) As i am always not so sure what code to send out as their might be other factors involved, I am going to post all my code...

why does isNaN always return true

javascript,nan,parseint
Having some trouble trying to validate strings that are numbers in JS. isNaN in particular seems to be misbehaving. <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>No Quirks!</title> </head> <body> <h1>JavaScript Test</h1> <button onclick="myNanIsTrue()">Is it a number?</button> <p id="writeToHTML"></p> <script type="text/javascript"> function myNanIsTrue() { var g = parseInt("40000000") + "<br...

parseInt() parses number literals with exponent incorrectly

javascript,node.js,numbers,parseint
I have just observed that the parseInt function doesn't take care about the decimals in case of integers (numbers containing the e character). Let's take an example: -3.67394039744206e-15 > parseInt(-3.67394039744206e-15) -3 > -3.67394039744206e-15.toFixed(19) -3.6739e-15 > -3.67394039744206e-15.toFixed(2) -0 > Math.round(-3.67394039744206e-15) 0 I expected that the parseInt will also return 0. What's...

Java: How to turn Hex into int?

java,numberformatexception,parseint
I'm working with BufferedImage (in PNG) and want to replace a colour with another. I have all colours stored as strings for easy handling but... for(int x=0;x<output.getWidth();x++) for(int y=0;y<output.getHeight();y++) if(output.getRGB(x,y)==Integer.parseInt("ffff00fe",16)) output.setRGB(x,y,Integer.parseInt("ffaaaaaa",16)); the resultant integers should be negative numbers, but it throws NumberFormatException when I do output.getRGB(x,y) it returns negative numbers...

Beginning Javascript Chapter 2 finishing exercise 2

javascript,parseint
I'm working through Beginning Javascript but can't get past Chapter 2 finishing exercise 2. The exercise is to correct this bit of code <!DOCTYPE html> <html lang="en"> <head> <title>Chapter 2, Finishing exercise 2</title> </head> <body> <script> var firstNumber = prompt("Enter the first number", ""); var secondNumber = prompt("Enter the second...