Home Tutorials Forums Articles Blogs Movies Library Employment Press

 ActionScript.org Forums Adding a zero after decimal point in totals?
 User Name Remember Me? Password
 Register FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

 02-13-2006, 10:43 PM #1 doh Registered User   Join Date: Feb 2006 Location: UK Posts: 3 Adding a zero after decimal point in totals? Hi, new here so sorry if this is a very basic question. I'm making a money-bank game where coins get dragged across to the piggy-bank and the total is displayed throughout. My problem is that, if say the amount is 10p, it is displayed as 0.1 rather than 0.10, or 1.1 for £1.10 etc. It would be great if I could get something to recognise those situations - adding 0 to make 0.10 - but not, say, to make 11p into 0.110. I put in some seriously clunky code which checked if the amount was a specific number (such as 0.1, 0.2, 0.3 etc) and told it to add a 0 on, but I'm sure there must be a simpler way of doing this? Specifically to maybe try and get it to only scan the number AFTER the decimal point and if there's only 1 number there, then add a 0 on afterwards to display the correct amount. I have a vague feeling it might have something to do with charAt(), but I'm not sure - it's not something I've looked at before. So any suggestions/help would be really appreciated.
 02-13-2006, 11:03 PM #2 oka_ bleh.     Join Date: Jun 2004 Location: melbourne.aust Posts: 303 Hey there, you're on the right track for sure. I'd convert the number to a string, and test how many characters there are after the decimal point. Something like... ActionScript Code: ```number = 1.5; foo = String(number); if (foo.substring(foo.indexOf(".", 0) + 1, foo.length).length == 1) {     foo += "0"; }``` -oka
 02-14-2006, 09:51 AM #3 doh Registered User   Join Date: Feb 2006 Location: UK Posts: 3 That's great, thanks. It works brilliantly with all the numbers with decimal points in them - only it doesn't seem to make any distinctions between whole numbers and decimals. It displays £20 for £2, £10 for £1, and so on. Any ideas on how to get around that? Thanks for the help so far. Last edited by doh; 02-14-2006 at 10:12 AM.
 02-14-2006, 11:37 AM #4 doh Registered User   Join Date: Feb 2006 Location: UK Posts: 3 OK, I've sorted something out - not entirely sure how it works, but it does (at least up to £99.00, anyhow.) Thought I'd put it up in case anyone else has a similar problem and needs a simple solution - some of the currency solutions I've seen are pretty complicated to me..!! Code: ```Number = myNumbr; foo = String (Number); if (foo.substring(foo.indexOf("."< 0) + 0, foo.length).length == 1) { displaytxt.text = " " + myNumbr + ".00"; } else if (foo.substring(foo.indexOf("."< 0) + 0, foo.length).length == 2) { displaytxt.text = " " + myNumbr + ".00"; } else if (foo.substring(foo.indexOf(".", 0) + 1, foo.length).length == 1) { displaytxt.text = " " + myNumbr + "0"; }``` If anyone can think of anything simpler/works over 100, let me know. All this is a bit beyond what I'm used to doing....

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home ActionScript Forums Group     ActionScript 3.0     ActionScript 2.0     ActionScript 1.0 (and below)     Simple Stuff (Newbies) Flash General Questions     Flash 10 General Questions     Flash 9 General Questions     Flash 8 General Questions     Other Flash General Questions Flex     Flex 2, 3 & 4     Flex 1 Extensions and Plugins     Components     JSFL - Extending Flash Desktop, Mobile and non-browser Environments     AIR (Apollo)     FlashLite / Portable Devices Development     Projectors and CDs Supporting Technologies     HTML and JavaScript     haXe     Server-Side Scripting     Flash Remoting     Flash Media Server General     Best Practices     Gaming and Game Development     Animation and Effects     Flashants Support Forum Community Boards     General Chat     Just for Kicks Challenges     Detention Flash In Action     Site Check     Cool Sites     Widgets Decommissioned     Projects and Positions CMS Forums     Announcements Board     Content Postings / Updates     Product Review Requests     CMS Technical Questions     Process Questions     Collaboration & Suggested Articles

 Similar Threads Thread Thread Starter Forum Replies Last Post johnkainn ActionScript 2.0 6 10-10-2005 04:38 PM bettypluto ActionScript 1.0 (and below) 0 05-11-2005 07:07 PM spikeuk22 ActionScript 1.0 (and below) 3 10-27-2004 11:20 AM Morg ActionScript 2.0 2 08-11-2004 08:39 AM wzrd ActionScript 1.0 (and below) 3 10-16-2001 02:42 PM

All times are GMT. The time now is 11:48 AM.

///