Page 1 of 1

Number formatting

Posted: Sun May 15, 2016 9:07 pm
by simon.schvartzman
Hi team, I'm at the very begining of my learning curve with LC and therefore please excuse me for this basic question. As a disclaimer before posting I spen a considerable amount of time searching on all available documentation and wasn't able to find the answer...

Assuming on a given field I have a number 12345678912 and when closing the field I want it to look like this: 123.456.789,12 (123,456,789.12 will also work).

How should I do it?

Many thanks in advance...

Re: Number formatting

Posted: Mon May 16, 2016 10:18 am
by jmburnod
Hi Simon,
Not sure that is the best way but this script do it

Code: Select all

on mouseUp
   put "12345678912" into t0
   put empty into t1
   put "," & char -2 to -1 of t0 into t1
   put char -5 to -3 of t0  before t1 
   put char -8 to -6 of t0 & "." before t1 
   put char -11 to -9 of t0 & "."  before t1 
   answer t1   & cr & "123.456.789,12 expected"
end mouseUp
Best regards
Jean-Marc

Re: Number formatting

Posted: Mon May 16, 2016 11:51 am
by simon.schvartzman
Jean-Marc, many thanks it works as expected!

Best!

Re: Number formatting

Posted: Mon May 16, 2016 2:02 pm
by jmburnod
Great,
but I guess you need the same for other numbers.
Function return a value and it is a good way
Something like this

Code: Select all

on mouseUp
   put setMynumber(12345678912)-- the result to message box
end mouseUp

function setMynumber pNumber
    put pNumber into t0
   put empty into t1
   put "," & char -2 to -1 of t0 into t1
   put char -5 to -3 of t0  before t1 
   put char -8 to -6 of t0 & "." before t1 
   put char -11 to -9 of t0 & "."  before t1 
   return t1
end setMynumber
All the best
Jean-Marc