Europen (or other) number style

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Europen (or other) number style

Post by MaxV » Mon Oct 21, 2013 2:21 pm

I used the following code for money in European (comma) format, example:

Code: Select all

europenum 12345.6
== 12'345,60
however it can be used as any other number format conversion:

Code: Select all

function reversed pString
    local tReversedString
    repeat with tChar = the length of pString down to 1
        put char tChar of pString after tReversedString
    end repeat    
    return tReversedString
end reversed

function europenum mynum
   set itemdelimiter to "."
   put the first item of mynum into integ
   put the second item of mynum into decimal
   if decimal is not empty then
      #this is optiona for money values
      if length(decimal) = 1 then
         put 0 after decimal
      end if      
      ##
      put "," before decimal
   else
      put ",00" into decimal #money values
   end if   
   put 1 into n
   put reversed(integ) into integ
   repeat for each char numb in integ      
      if n = 4 then
         put "'" before decimal
         put 1 into n
      end if      
      put numb before decimal
      add 1 to n
   end repeat
   return decimal
end europenum
I suggest to use always standard Livecode format for numbers and convert them just for display values.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply