Page 1 of 2 12>
Topic Options
#202224 - 2011-05-14 05:25 PM Is this a bug?
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
The below returns "2147483647"...

 Code:
? Val("11111111111")

get $


Is this a bug, or is there some kind of programming logic that I'm not recognizing that justifies that result?

Top
#202225 - 2011-05-14 05:51 PM Re: Is this a bug? [Re: ShaneEP]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
I ran into something similar a few years back... here is Ruud's comments on it: http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=180025#Post180025
Top
#202226 - 2011-05-14 06:03 PM Re: Is this a bug? [Re: Allen]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Gotcha...
Top
#202227 - 2011-05-14 06:14 PM Re: Is this a bug? [Re: ShaneEP]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Did you try using CDBL()?
 Code:
$str="11111111111"
$dbl=cdbl($str)
? vartypename($dbl)
? $dbl
? $dbl+1

Top
#202229 - 2011-05-14 07:25 PM Re: Is this a bug? [Re: Allen]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
That solved the problem...thanks a bunch Allen.
Top
#202230 - 2011-05-14 09:07 PM Re: Is this a bug? [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Any ideas on trying to get the same result as an cdbl, but without the scientific notation beyond 1 trillion? lol
Top
#202231 - 2011-05-14 09:09 PM Re: Is this a bug? [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Just some insight...I'm writing a recursive function that converts numbers into text. Not sure if there is any use for numbers that high anyways...but it just bugs me to be limited.
Top
#202235 - 2011-05-14 10:48 PM Re: Is this a bug? [Re: ShaneEP]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
I'm not sure I follow... how about an example of what you have and what you want it to look like.
Top
#202236 - 2011-05-14 11:04 PM Re: Is this a bug? [Re: Allen]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Just a function that when supplied a number it returns the text version of that number...

Num2Text("999999999999999") returns "Nine Hundred Ninety Nine Trillion Nine Hundred Ninety Nine Billion Nine Hundred
Ninety Nine Million Nine Hundred Ninety Nine Thousand Nine Hundred Ninety Nine".

But if I had 1 more digit the numbers start getting truncated. For example CDbl turns "1999999999999999" into 2E+015 which obviously screws up the final results. I think I'm about at the point of not caring if it works over 999 trillion ;\)

Top
#202244 - 2011-05-15 11:58 PM Re: Is this a bug? [Re: ShaneEP]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
try: formatnumber()

not sure but it might have something to do with how many significant numbers you can have in a double or float.
so, translating to and back from string results in loss of information. just my two cents.
_________________________
!

download KiXnet

Top
#202245 - 2011-05-16 06:20 AM Re: Is this a bug? [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
oh, and with formatnumber you should force the grouping and then just calculate the string for the three and append the ...
nevermind, I will show...
_________________________
!

download KiXnet

Top
#202246 - 2011-05-16 07:18 AM Re: Is this a bug? [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ehm. ok. I see bugs everywhere now.
even the formatnumber() doesn't behave correctly:
 Code:
$string="1999999999999999"
$string " as text is about the same as:" ?
"	" num2text($string)
get $

function num2text($n)
dim $m,$d,$t,$g,$o
 $n=""+formatnumber($n,,,,1)
 $m=split(" thousand million billion trillion omg well?")
 $t='',one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,eighteen,nineteen
 $d='',twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety

 for each $g in split($n)
  if len($g)=3
   $o=$t[left($g,1)]+" hundred"
  else
   $o=''
  endif
  $g=right($g,-1)
  if 20>$g
   $o=$o+$t[0+$g]
   if 0=$n
    $o=zero
   endif
  else
   $g ?
   $o=$o+$d[1*$g/10]+" "+$t[right($g,1)]
  endif
  $num2text=trim($num2text+" "+$o+" "+$m[ubound(split($n))])
 next
endfunction
_________________________
!

download KiXnet

Top
#202249 - 2011-05-16 05:17 PM Re: Is this a bug? [Re: Lonkero]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Here is what I had come up with...It still only works up to 999 trillion, but it works. I got an array reference our of bounds on line 27 of your code jooel.

 Code:
? Num2Text("999999999999999")

if @Error ? @Error endif

get $

Function Num2Text($n)
   Dim $ones,$tens,$magnitudes
   $ones="","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten",
      "Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"
   $tens="","Ten","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"
   $magnitudes="Hundred","Thousand","Million","Billion","Trillion"
   if $n<>CDbl($n) exit 87 endif
   $n = CDbl($n)
   if $n<1 exit 87 endif
   Select
      Case Len($n)=1
         $Num2Text=$ones[$n]
      Case Len($n)=2
         if left($n,1)=1
            $Num2Text=$ones[$n]
         else
            $Num2Text=Trim($tens[val($n/10)]+" "+Num2Text(right($n,1)))
         endif
      Case Len($n)=3
         $Num2Text=Trim($ones[left($n,1)]+" Hundred "+Num2Text(right($n,2)))
      Case Len($n)>3
         $Num2Text=Trim(Num2Text(left($n,len($n)-((len($n)-1)/3)*3))+" "+
                   $magnitudes[(len($n)-1)/3]+" "+Num2Text(right($n,((len($n)-1)/3)*3)))
   EndSelect
EndFunction

Top
#202251 - 2011-05-16 05:56 PM Re: Is this a bug? [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
oh, that code seems to have some debug output as well.
did the code and realised it wasn't working with any twist before posted.
_________________________
!

download KiXnet

Top
#202253 - 2011-05-16 07:50 PM Re: Is this a bug? [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
and yes you got it, cause even though, formatnumber() gives a nice output to console of "1 999 999 999 999 999" etc, you can't actually work with that number.
even if it shows it like that on the console, you can't divide that number and you can't split it.
it is of subtype nonvariant-nonstring-nonnumeric something something. useless?
_________________________
!

download KiXnet

Top
#202254 - 2011-05-16 10:41 PM Re: Is this a bug? [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
this should work, if working code is all you need:
 Code:
$string="1999999999999999" ?
$string " as text is about the same as:" num2text($string)
$string="2999" ?
$string " as text is about the same as:" num2text($string)
get $

function num2text($n)
dim $m,$d,$t,$g,$o,$l
 $n=""+$n ;making sure it's string
 $m=split(" thousand million billion trillion quadrillion quintillion sextillion septillion octillion nonillion decillion undecillion duodecillion tredecillion")
 $t='',one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,eighteen,nineteen
 $d='','',twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety

 do
  $l=len($n)
  if $l mod 3
   $g=left($n,$l mod 3)
   $n=right($n,-($l mod 3))
  else
   $g=left($n,3)
   $n=right($n,-3)
  endif
  if len($g)=3
   $o=" "+$t[left($g,1)]+" hundred"
   $g=right($g,-1)
  endif
  if 20>$g
   $o=$o+$t[0+$g]
   if 0=$n
    $o=" zero"
   endif
  else
   $o=$o+" "+$d[1*$g/10]+" "+$t[right($g,1)]
  endif
  $num2text=trim($num2text+$o+" "+$m[($l-1)/3])
  $o=''
 until len($n)<3
endfunction


Edited by Lonkero (2011-05-16 10:41 PM)
_________________________
!

download KiXnet

Top
#202255 - 2011-05-16 11:48 PM Re: Is this a bug? [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
lol...
posting it as udf...
_________________________
!

download KiXnet

Top
#202257 - 2011-05-16 11:57 PM Re: Is this a bug? [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
there: http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=202256

supports even decimals :P
_________________________
!

download KiXnet

Top
#202267 - 2011-05-19 02:17 AM Re: Is this a bug? [Re: Lonkero]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Guess I should have posted here, but I posted to your UDF

Thanks for sharing Lonk

Top
#202269 - 2011-05-19 03:00 PM Re: Is this a bug? [Re: NTDOC]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
did you figure out your output issue?
_________________________
!

download KiXnet

Top
Page 1 of 2 12>


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

Who's Online
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.074 seconds in which 0.023 seconds were spent on a total of 14 queries. Zlib compression enabled.

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