Number to text

John Dixon dixonja at hotmail.co.uk
Wed Dec 8 18:57:50 EST 2010


Make two fields... one button

button script...

on mouseUp
   put empty into fld 2
   
   put ("one","two","three","four","five","six","seven","eight","nine") into singleNumbers
   put ("eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen") into mixedUpNumbers
   put ("ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety") into tensNumbers
   
   put the number of chars of fld 1 into theCharCount
   -----------------------------------------------------
   if theCharCount = 1 then
      put item (char 1 of fld 1) of singleNumbers into theTextNumber
   end if
   -----------------------------------------------------
   if theCharCount = 2 then
      if char 2 of fld 1 = 0 then
         put item (char 1 of fld 1) of tensNumbers into theTextNumber
      end if
      
      if char 1 of fld 1 =  1 AND char 2 of fld 1 <> 0 then
         put item (char 2 of fld 1) of mixedUpNumbers into theTextNumber
      end if
      
      if char 1 of fld 1 > 1 AND char 2 of fld 1 <> 0 then
         put item (char 1 of fld 1) of tensNumbers into theTextNumber
         put space & item (char 2 of fld 1) of singleNumbers after theTextNumber
      end if
   end if
   -----------------------------------------------------
   if theCharCount = 3 then
      put item (char 1 of fld 1) of singleNumbers && "hundred" into theTextNumber
      
      if char 2 of fld 1 <> 0 then
         put " and" &&  item (char 2 of fld 1) of tensNumbers after theTextNumber
      end if
      
      if char 3 of fld 1 = 0 then
         put  item (char 3 of fld 1) of singleNumbers after theTextNumber
      end if
      
      if char 3 of fld 1 > 0 then
         put space & item (char 3 of fld 1) of singleNumbers after theTextNumber
      end if
   end if
   -----------------------------------------------------
   put theTextNumber into fld 2
end mouseUp

> 
> Hi any Idea on how to go about calculating numbers to text eg. 100, One
> Hundred, ?
> Thanks, Hershel

 		 	   		  


More information about the Use-livecode mailing list