Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-30-2003, 01:39 AM   #1
Whelan_Web
Registered User
 
Join Date: Apr 2003
Location: Ireland
Posts: 6
Lightbulb Returning a dollar value

Hello is their anyone out their who can tell me how to format a value in a dynamic text box so that it ruturns a dollar value

example when it does a calculation it returns in the text box something like

1000.236 but what I need is $1000.23 or 1000.23

thanks alot

David
Whelan_Web is offline   Reply With Quote
Old 04-30-2003, 04:10 AM   #2
jefmyers
Registered User
 
Join Date: Feb 2002
Posts: 24
Default

not sure if this is what your talking about
ActionScript Code:
x = 1000.236      y = Math.round(x * 100) / 100      trace(y)

don't konw if this helps or not. it rounds up to the cent. you might format it diff, i don't know what you want to do with it?
-jef
jefmyers is offline   Reply With Quote
Old 04-30-2003, 04:19 AM   #3
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

Howdy...

You could search the forum to find more information faster...

I did search the forum with 'currency', and I think this thread could be useful for you...


Keyword: currency cbcurrency
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Old 02-09-2005, 02:17 PM   #4
realdude
Registered User
 
Join Date: Feb 2005
Posts: 5
Default Expanding the Question- can an input field be formatted?

Greetings,

I have searched and read everything I can find, both in this forum and just about everywhere else, and can't seem to find a solution. Is there a way to format a text input field so that when the field is exited the numbers, at the very least, is formatted with commas? Please be gentle, struggling student here.

Thanks
realdude is offline   Reply With Quote
Old 02-09-2005, 06:44 PM   #5
tg
done
 
Join Date: Jun 2001
Location: portland, or
Posts: 8,106
Default

http://proto.layer51.com/d.aspx?f=164
__________________
tg
---
what the hell was i thinking?
tg is offline   Reply With Quote
Old 02-09-2005, 07:49 PM   #6
realdude
Registered User
 
Join Date: Feb 2005
Posts: 5
Default How do I apply this?

Sorry to be so dense, but I'm not quite sure how to apply this. Let me take a stab at it and please correct me if I'm wrong.

1. create a frame, actions and past the code there
2. create a text field (input or dynamic)
3. Name the field, say input1
4. What next? How do I call the function?

Boy, do I feel dumb!

Thanks
realdude is offline   Reply With Quote
Old 02-12-2005, 07:34 PM   #7
speedlemon
Registered User
 
speedlemon's Avatar
 
Join Date: Jun 2004
Location: U.S.A.
Posts: 108
Default

PHP Code:
onEnterFrame = function () {
    
outputtext "$"+Math.round(inputtext*100)/100;
}; 
problem solved.

btw to call a function-

PHP Code:
my_function() 

Last edited by speedlemon; 02-12-2005 at 07:39 PM.
speedlemon is offline   Reply With Quote
Old 02-13-2005, 07:46 PM   #8
tg
done
 
Join Date: Jun 2001
Location: portland, or
Posts: 8,106
Default

try it this way.... then you don't have the loop running in the background.
ActionScript Code:
/************************      prototypes       ********************************/ // author: Justlar  [+], Submitted: 06.17.01 3p  //http://proto.layer51.com/d.aspx?f=164 Number.prototype.Currency = function(uom) { // uom = Unit of Measure.  Default set to US Dollars ($).     var temp = this.toString();     var dot = temp.indexOf(".", 0);     if(uom==null) { uom="$" }     if (dot<=0) {         var thedollar = temp;         var cents = "00";     } else {         var thedollar = temp.substr(0,dot);         var cents = temp.substr(dot+1,temp.length);     }     if (thedollar.length>3) {         var d_Len = thedollar.length;         var d_brk = d_Len/3;         if ((d_Len % 3)==0) {             var d_brk = (d_Len/3)-1;         }         for (var i=1; i<=d_brk; i++) {             var thedollar = thedollar.substr(0,(d_Len-(3*i)-(i-1))) + "," + thedollar.substr((d_Len-(3*i)-(i-1)),(3*i)+(i-1));             d_Len = thedollar.length;         }      }     dollars = thedollar;     if (cents.length>2) {         cents = Math.round(cents.substr(0,2) + "." + cents.substr(2,cents.length));     } else if (cents.length==1){         cents = cents + "0";     }     return uom + dollars + "." + cents; } // author: moock //http://www.oreillynet.com/pub/a/javascript/2003/05/20/colinmoock.html TextField.prototype.onKeyDown = function () {   if (Key.getCode() == Key.ENTER) {     changeTextToDollars();     //trace('enter key hit');   } }; changeTextToDollars=function(){     var cur=Number(dollars_txt.text);     //trace(cur);     dollars_txt.text=cur.Currency(); }; Key.addListener(dollars_txt);

note. there was a bug in currency prototype, but it is fixed in this code. (it wasnt showing dollar values less than 100

i also added a textfield method written by colin moock. this allows the textfield to capture when the enter key was hit. so that the user can enter their dollar amount and hit enter, and the currency will format.

the keylistener allows the specified textfield to 'listen' for the any key to be hit.

you can also add a 'submit button' and have that call the changetexttodollars function also.

to get this code to work for you do the following:
copy and paste the above code into a new fla.
put an input box on the stage.
give the input box an instance name of 'dollars_txt'


you can also change it a bit so when the dollars_txt looses focus, the input is formatted. you may also want to put some error handling in there so that can catch when someone puts something other than a number in the input box.
it should work fine. it does for me.
__________________
tg
---
what the hell was i thinking?

Last edited by tg; 02-13-2005 at 07:48 PM.
tg is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:33 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.