ShaneEP
(MM club member)
2011-05-14 05:25 PM
Is this a bug?

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?


AllenAdministrator
(KiX Supporter)
2011-05-14 05:51 PM
Re: Is this a bug?

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

ShaneEP
(MM club member)
2011-05-14 06:03 PM
Re: Is this a bug?

Gotcha...

AllenAdministrator
(KiX Supporter)
2011-05-14 06:14 PM
Re: Is this a bug?

Did you try using CDBL()?
 Code:
$str="11111111111"
$dbl=cdbl($str)
? vartypename($dbl)
? $dbl
? $dbl+1


ShaneEP
(MM club member)
2011-05-14 07:25 PM
Re: Is this a bug?

That solved the problem...thanks a bunch Allen.

ShaneEP
(MM club member)
2011-05-14 09:07 PM
Re: Is this a bug?

Any ideas on trying to get the same result as an cdbl, but without the scientific notation beyond 1 trillion? lol

ShaneEP
(MM club member)
2011-05-14 09:09 PM
Re: Is this a bug?

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.

AllenAdministrator
(KiX Supporter)
2011-05-14 10:48 PM
Re: Is this a bug?

I'm not sure I follow... how about an example of what you have and what you want it to look like.

ShaneEP
(MM club member)
2011-05-14 11:04 PM
Re: Is this a bug?

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 ;\)


LonkeroAdministrator
(KiX Master Guru)
2011-05-15 11:58 PM
Re: Is this a bug?

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.


LonkeroAdministrator
(KiX Master Guru)
2011-05-16 06:20 AM
Re: Is this a bug?

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...


LonkeroAdministrator
(KiX Master Guru)
2011-05-16 07:18 AM
Re: Is this a bug?

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


ShaneEP
(MM club member)
2011-05-16 05:17 PM
Re: Is this a bug?

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


LonkeroAdministrator
(KiX Master Guru)
2011-05-16 05:56 PM
Re: Is this a bug?

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.


LonkeroAdministrator
(KiX Master Guru)
2011-05-16 07:50 PM
Re: Is this a bug?

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?


LonkeroAdministrator
(KiX Master Guru)
2011-05-16 10:41 PM
Re: Is this a bug?

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


LonkeroAdministrator
(KiX Master Guru)
2011-05-16 11:48 PM
Re: Is this a bug?

lol...
posting it as udf...


LonkeroAdministrator
(KiX Master Guru)
2011-05-16 11:57 PM
Re: Is this a bug?

there: http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=202256

supports even decimals :P


NTDOCAdministrator
(KiX Master)
2011-05-19 02:17 AM
Re: Is this a bug?

Guess I should have posted here, but I posted to your UDF

Thanks for sharing Lonk


LonkeroAdministrator
(KiX Master Guru)
2011-05-19 03:00 PM
Re: Is this a bug?

did you figure out your output issue?

NTDOCAdministrator
(KiX Master)
2011-05-23 08:20 PM
Re: Is this a bug?

Well seems it's ongoing and the discussion is taking place in the UDF forum now.

LonkeroAdministrator
(KiX Master Guru)
2011-05-24 03:50 AM
Re: Is this a bug?

yea...
your console window can't handle the output without wordwrap from that example.