Page 1 of 1

Extract numbers before and after decimal separator

Posted: Thu Mar 12, 2015 11:26 am
by davidmills
on mouseDown
If field 1 as an example contains 197.256221
How do I extract all the numbers before a decimal point and place those into field 2 (in the example would be 197)
and then also extract all the numbers after a decimal point and place those into field 3 (in the example would be 256221)
Thanks
Dave

Re: Extract numbers before and after decimal separator

Posted: Thu Mar 12, 2015 11:32 am
by Thierry
davidmills wrote: How do I extract all the numbers before a decimal point
and then also extract all the numbers after a decimal point
David,

Code: Select all

   put "xxx 197.256221  yyyy " into T
   if MatchText( T, "(\d+)\.(\d+)", n1, n2) then
      put n1 into fld 1
      put n2 into fld 2
   end if
HTH,

Thierry

PS: Someone else might certainly give you a more 'Livecodish' solution...

Re: Extract numbers before and after decimal separator

Posted: Thu Mar 12, 2015 1:24 pm
by magice

Code: Select all

put fld "1" into tNum --You should not name fields with only a number, it can cause errors
set the itemDelimiter to "."
put item 1 of tNum into containerForWholeNumber
put item 2 of tNum into containerForDecimalNumber

Re: Extract numbers before and after decimal separator

Posted: Thu Mar 12, 2015 9:54 pm
by davidmills
Thank you both for your help.
Dave