number formatting

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
byg
Posts: 10
Joined: Fri Apr 12, 2013 6:33 pm

number formatting

Post by byg » Mon Oct 07, 2013 2:24 am

Hi, I thought this would be easy but no. Basically I would like to be able to format a number to display a currency in this case dollar ex. $123.45
I read the information in dictionary and search thru the forum for number formatting and glance thru apps examples with not much success. Any help on this would be appreciated, tutorial, guide to read anything. I build a test stack to see how formatting would work. The example below does not give me an error but if I enter 123.4567 I get 123.4567 in both cases.TIA





on mouseUp
set the numberformat to "0.00"
ask "enter a number"
put it into field "mine"
answer it
end mouseUp

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: number formatting

Post by Simon » Mon Oct 07, 2013 2:43 am

Hi byg,
Here is the funny little line in the dictionary that gets overlooked:
Use the numberFormat property to specify the results of numeric calculations,
Note the last 5 words :)

I think this will do it:
on mouseUp
set the numberformat to "0.00"
ask "enter a number"
add 0 to it
put it into field "mine"
answer it
end mouseUp
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: number formatting

Post by dunbarx » Mon Oct 07, 2013 2:46 am

Hi right back to you.

An oldie but goodie. The numberformat property will not express itself unless an arithmetic operation is performed first. Try this:

Code: Select all

on mouseUp
set the numberformat to "0.00"
ask "enter a number"
answer it + 0
end mouseUp
The addition seems superfluous, and in every sense except making the format work, it is.

Craig Newman

byg
Posts: 10
Joined: Fri Apr 12, 2013 6:33 pm

Re: number formatting

Post by byg » Mon Oct 07, 2013 3:21 am

hI to both of you , amazingly simple when you know it, "overlook" is right , thanks all.
byg

Post Reply