Page 1 of 1 1
Topic Options
#34806 - 2003-01-06 05:13 PM Long Integers revisited
h00kupz Offline
Fresh Scripter

Registered: 2002-07-17
Posts: 14
Loc: Atlanta
I have a problem with long integers when trying to convert a number from what kix would interperet as a string to a floating point value. With this snipet of code:
quote:

Dim $x
$x = 389955656444
$x = $x + 355658985665.0
? $x
?

How would I got about first converting $x to a floating point value in order for the addition function to return the proper value? I tried outputting the info to a file and reading it back in after adding the decimal like so:

quote:

Dim $x
Dim $y
Dim $z
$z = 355688999545.0
$x = "389955656444"
Open(1,%TEMP%\Test.txt,5)
WriteLine(1,"$x.0")
Close(1)
Open(1,%TEMP%\Test.txt,2)
$y = ReadLine(1)
? $y
?
Close(1)
$x = ($y + $z)
? $x
?

To no avail. Any Ideas? Output displays 389955656444.0355688999545 as if it's trying to combine the 2 as strings. Running v4.12 of kix32.exe.
_________________________
Select * from users where clue > 0 [b]0 rows affected.[/b]

Top
#34807 - 2003-01-06 05:16 PM Re: Long Integers revisited
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Look up CINT, CDBL, FIX in the KiXtart Manual.
code:
$x = cdbl('389955656444')
$x = 389955656444.0
$x = $x + 355658985665.0
? $x
?

there has also been a long discussion on integer/doubles/floats and variable type precedences a couple of months ago. Please use the KiXtart BBS search to retrieve that topic.
_________________________
There are two types of vessels, submarines and targets.

Top
#34808 - 2003-01-06 11:59 PM Re: Long Integers revisited
h00kupz Offline
Fresh Scripter

Registered: 2002-07-17
Posts: 14
Loc: Atlanta
Ok I feel like a dumb a**, Why wouldn't the following code work... Can you not pass cdbl a variable? I tried it the following 2 ways:

code:
Dim $w
Dim $x
Dim $y
Dim $z
$w = "'389955656444'"
$x = CDbl($w)
$y = 355688999545.0
$z = $x + $y
? $z
?

and...

code:
Dim $w
Dim $x
Dim $y
Dim $z
$w = 389955656444
$x = CDbl('$w')
$y = 355688999545.0
$z = $x + $y

? $z
?

I tried searching the forum for cdbl() syntax to no avail... [Confused]
_________________________
Select * from users where clue > 0 [b]0 rows affected.[/b]

Top
#34809 - 2003-01-07 03:13 AM Re: Long Integers revisited
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Wouldnt this work? I dont think you need the single quotes in your first example...

code:
 
Dim $w
Dim $x
Dim $y
Dim $z
$w = "389955656444"
$x = CDbl($w)
$y = 355688999545.0
$z = $x + $y
? $z
?


Top
#34810 - 2003-01-07 04:21 AM Re: Long Integers revisited
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
or even adding first a zero-valued float:
$string="12.3"
$num=52
$resulting_float=0.0+$string+$num
_________________________
!

download KiXnet

Top
#34811 - 2003-01-07 03:31 PM Re: Long Integers revisited
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
CDBL() is in the KiXtart Manual, I believe v4.12+
_________________________
There are two types of vessels, submarines and targets.

Top
#34812 - 2003-01-07 11:27 PM Re: Long Integers revisited
h00kupz Offline
Fresh Scripter

Registered: 2002-07-17
Posts: 14
Loc: Atlanta
Thanks Shane. You were right that got everything straightened out. So if you are look for a long integer solution here it is short and sweet. (Sorry to put that in there however I haven't found a definitive answer in any other threads). Thanks to everyone for setting me straight. [Big Grin]
_________________________
Select * from users where clue > 0 [b]0 rows affected.[/b]

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1013 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.058 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org