...

View Full Version : parseInt(abc)



tanpl3
11-12-2004, 09:35 AM
i have problem with this

function Total()
{
abc = "1,236.00"
cde = "1,000.00"

final = parseInt(abc) + parseInt(cde);

}

the result i get is "2", statement wrong??
Pls help..10s

fci
11-12-2004, 09:41 AM
You posted in the wrong forum.. and.. no comma is necessary.. and you should probably be using numbers instead of strings but I didn't change that..


function Total()
{
var abc = "1236.00";
var cde = "1000.00";
var final = parseInt(abc) + parseInt(cde);
}


...

Roelf
11-12-2004, 11:06 AM
afaik, parseInt starts parsing the string from the left, the first position should be numeric. Whenever it finds a non-numeric character (fe your comma), it stops parsing. The numeric part, is converted to int var-type.
So parseInt("1236.00"); should give int: 1
and parseInt("1000.00"); should give int: 1
together that makes int: 2

Kor
11-12-2004, 01:20 PM
So parseInt("1236.00"); should give int: 1
and parseInt("1000.00"); should give int: 1

Wrong.
parseInt("1236.00"); should give int 1236
and parseInt("1000.00"); should give int: 1000

Anyway, javascript does not accept number in format

ddd,ddd
so get rid of that comma

Roelf
11-12-2004, 03:56 PM
:rolleyes:

oops, i meant to copy the values with the comma in it so it was meant this way:
So parseInt("1,236.00"); should give int: 1
and parseInt("1,000.00"); should give int: 1

<note to="self">better watch out before you press submit reply</note>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum