|
-
October 23rd, 2002, 04:26 AM
#1
Converting string to number
Hello All,
I am facing problem in converting string to number.
I have two strings...
strFrom = "123456789123456789123";
strTo = "123456789123456789130";
I converted them into integers......by using parseInt and Math.abs
But output of parseInt("123456789123456789123") is not proper integer output. Same is happening with Math.abs.
The difference of these two strings is supposed to be 7............. after converting into integers
but i am not able to get that................
can anyone help me...............
Thanks in advance..
Shraddha Biyani
-
October 23rd, 2002, 10:00 AM
#2
Well. This 'integer' is far too large to be contained in any programming language's interger datacarrier. I assume you're using Java, from the functions you mentioned. Try using a double, instead, but I think even that's too small. Why the huge number?
Captain Obvious
Documentation is your friend
-
October 23rd, 2002, 12:18 PM
#3
it's not java, it's javascript, very different.
there is no double type in javascript....there is no integer type, the browser does the deciding, you just declare
var someVariable;
try this
Code:
<html>
<body>
<script language="javascript">
//can only handle a 16 digit number...i suggest breaking apart somehow then working with peices of it.
var first="9999999999999999";
var second="9999999999999998";
var third=first-second;
//or var third=parseInt(first)-parseInt(second); both have same result
alert(third);
</script>
</body>
</html>
i tested it and it works fine
C G C F A D--Feel the Noise
"When your life goes nowhere and leads back to me, doesn't that tell you something?"
~Gray Area Fury
-
October 23rd, 2002, 12:27 PM
#4
Disregarding it being javascript, and there not being any datatypes in said language, the number was still too big. ;p
Captain Obvious
Documentation is your friend
-
October 23rd, 2002, 12:42 PM
#5
yes, that's why i noted it in my sample code.
beyond that, he was doing it wrong anyway, a string and an integer are interchangeable in javascript (as long as they are numeric characters)
C G C F A D--Feel the Noise
"When your life goes nowhere and leads back to me, doesn't that tell you something?"
~Gray Area Fury
-
October 23rd, 2002, 12:43 PM
#6
Captain Obvious
Documentation is your friend
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|