Currency display in a field

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
petero
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 59
Joined: Sat Jan 20, 2007 4:09 am

Currency display in a field

Post by petero » Wed Sep 19, 2007 3:08 am

How do you get a field to display its contents in currency format (i.e. with $ sign and commas)?

Thank you for your help.

Peter

Mark Smith
Posts: 179
Joined: Sat Apr 08, 2006 11:08 pm
Contact:

Post by Mark Smith » Sat Sep 22, 2007 8:00 pm

Peter, there isn't a built in property of fields to do this.

You have the choice of a handler in the field script, or a function in your stack or a library.

The first might be, in the field's script:

Code: Select all

on setCurrencyText pAmount
  put "$" & format("%1.2f", pAmount) into me
end setCurrencyText
so then, instead of

Code: Select all

put 20.4 into fld "someField"
you could

Code: Select all

send "setCurrencyText 20.4" to fld "someField"

Or, (and I prefer this idea) have a function like the one above that you call when putting a number into the field:

Code: Select all

put makeCurrency(20.4) into fld "someField"

Hope this helps,

Mark

Post Reply