#202224 - 2011-05-14 05:25 PM
Is this a bug?
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
The below returns "2147483647"...
? 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
KiX Supporter
Registered: 2003-04-19
Posts: 4545
Loc: USA
|
|
Top
|
|
|
|
#202227 - 2011-05-14 06:14 PM
Re: Is this a bug?
[Re: ShaneEP]
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4545
Loc: USA
|
Did you try using CDBL()?
$str="11111111111"
$dbl=cdbl($str)
? vartypename($dbl)
? $dbl
? $dbl+1
|
Top
|
|
|
|
#202236 - 2011-05-14 11:04 PM
Re: Is this a bug?
[Re: Allen]
|
ShaneEP
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
|
|
|
|
#202246 - 2011-05-16 07:18 AM
Re: Is this a bug?
[Re: Lonkero]
|
Lonkero
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:
$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
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.
? 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
|
|
|
|
#202254 - 2011-05-16 10:41 PM
Re: Is this a bug?
[Re: Lonkero]
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
this should work, if working code is all you need:
$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
|
|
|
|
#202257 - 2011-05-16 11:57 PM
Re: Is this a bug?
[Re: Lonkero]
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
|
Top
|
|
|
|
#202267 - 2011-05-19 02:17 AM
Re: Is this a bug?
[Re: Lonkero]
|
NTDOC
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
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 515 anonymous users online.
|
|
|