Formatting Numbers

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Formatting Numbers

Post by phaworth » Tue Jul 07, 2009 7:53 pm

Got several fields in my database that are currency values. Linking a field on a form to any of them results in just the raw number being displayed, for example 10.0. What I need is for the number to be displayed as $10.00. Some of them will need comma(s) inserted as thousands separators and the formatting also needs to deal with negative values.

Do I have to write my own code to take care of all that or are there built-in functions to take care of it?

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Tue Jul 07, 2009 9:20 pm

I'm afraid you'll have to "roll your own" - though you can search the use-revolution list archives to find some past attempts and adapt those to your needs. Here's one of my versions of a numeric field with separators http://article.gmane.org/gmane.comp.ide ... .user/8374, cobbled together from several earlier posts.

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Post by phaworth » Tue Jul 07, 2009 9:55 pm

I'm beginning to think Revolution is not for me. I'm impressed with a lot of its functionality but I don't really want to spend hours writing code for really basic things like formatting numbers and being able to pick a date from a calendar grid.

shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Contact:

Post by shadowslash » Tue Jul 07, 2009 10:14 pm

phaworth wrote:I'm beginning to think Revolution is not for me. I'm impressed with a lot of its functionality but I don't really want to spend hours writing code for really basic things like formatting numbers and being able to pick a date from a calendar grid.
Don't give up now, you'll see once you get used to Rev, you'll notice that you won't need to spend hours writing code for really basic things anymore... Everybody has to start at the bottom right? Image
Parañaque, Philippines
Image
Image

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Post by phaworth » Wed Jul 08, 2009 1:01 am

Right, there's always a learning curve, I'd just rather spend it learning how to deal with the logic of my application than on implementing basic formatting like this.

But I'm still trying....
Pete

paul_gr
Posts: 319
Joined: Fri Dec 08, 2006 7:38 pm

Post by paul_gr » Wed Jul 08, 2009 1:27 am

Look in RevOnline and check out the AccountancyFormat() stack.

Paul

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Post by phaworth » Wed Jul 08, 2009 1:37 am

Perfect! Thanks.
Pete

whelkybaby
Posts: 47
Joined: Sat Nov 17, 2007 6:04 pm

Post by whelkybaby » Fri Jul 10, 2009 12:10 am

Yay - that stack's my work! Awesome that I've been able to help. :)

Steve

www.theworcestersource.com

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Post by phaworth » Wed Jul 15, 2009 10:12 pm

Works great, thanks. One question - is there a way to not have any thousands separator? Right now, leaving that field empty inserts a comma.
Pete

whelkybaby
Posts: 47
Joined: Sat Nov 17, 2007 6:04 pm

Post by whelkybaby » Wed Jul 15, 2009 10:44 pm

Easy peasy.

Open up the script and delete this line:

Code: Select all

if pSeparator="" then put "," into pSeparator
Of course, if you want to put a comma in there, you'll now have to enter it as one of the parameters of the function.

Cheers,


Steve

www.theworcestersource.com

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Post by phaworth » Wed Jul 15, 2009 10:52 pm

Thanks Steve, works great. By the way, nice blog - as a new user of Rev, I need all the reference material I can get. Your tree display is something I had built in to the last dev tool I was using and have been wondering how to deal with it in Rev.
Pete

whelkybaby
Posts: 47
Joined: Sat Nov 17, 2007 6:04 pm

Post by whelkybaby » Fri Jul 17, 2009 6:35 pm

Thanks for the nice comment about the blog!

The tree component isn't far off being finished now. I'm currently in the middle of writing the manual to go with it. I'll probably be stuck indoors this weekend (rain, rain, go away!) and may have a beta by the end of Sunday.

I doubt that finding a few testers won't be too hard!


Steve

www.theworcestersource.com

Post Reply