Home Tutorials Forums Articles Blogs Movies Library Employment Press

 ActionScript.org Forums decimal places
 Register FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

 05-23-2002, 10:44 PM #1 rcr639 Registered User   Join Date: May 2002 Location: - Posts: 19 decimal places is there any way I can make a field that is calculated from two other fields only have a certain amount of decimal places it could either chop of at 2 decimal places or round it to 2 decimal places
 05-23-2002, 10:55 PM #2 tg done   Join Date: Jun 2001 Location: portland, or Posts: 8,106 __________________ tg --- what the hell was i thinking?
 05-24-2002, 01:31 AM #3 rcr639 Registered User   Join Date: May 2002 Location: - Posts: 19 Here is my script. on (release) { _root.valp = Number(_root.init)*Number(_root.shar); valp *= 100; valp = Math.round(valp); valp = valp/100; _root.pric = Number(_root.late)*Number(_root.shar)-Number(_root.init)*Number(_root.shar); pric *= 100; pric = Math.round(pric); pric = pric/100; _root.valn = Number(_root.late)*Number(_root.shar); valn *= 100; valn = Math.round(valn); valn = valn/100; } Here are the problems. When the hundreths place is 0, for example if the program calculates this number 8.404 it will display 8.4 I need it to display 8.40. Also if the number is 8.405 or anything like that it doesn't round it to 8.41 it leaves it as 8.40 or in this case 8.4. How do I fix both of these problems. Is there anyway to streamline the script I have now or is it fine?
 05-24-2002, 01:37 AM #4 rcr639 Registered User   Join Date: May 2002 Location: - Posts: 19 could this script be incorporated someway so that all calculated numbers round to 2 decimal places http://www.actionscript.org/forums/s...decimal+places
 05-26-2002, 03:14 AM #5 Jesse ActionScript.org Founder     Join Date: Nov 2000 Location: New York Posts: 8,736 Flash will not retain zeros after the last significant digit. Otherwise 1 would be 1.00000000... If you want to display the zero at the end you can use Robert's script but that returns a string so you have to remember to convert the result to a number before trying to do any more mathematical operations with it: ActionScript Code: ```var1 = 123.24; var2 = 345.56; display = Math.formatDecimals(var1+var2, 2); var3 = Number(display); trace (display); trace (var3);``` Here you can use var3 for math operations (like addition, subtraction, etc) but you can't use display, as it is a string, for display purposes only. __________________ Cheers Jesse Stratford ActionScript.org Cofounder Please don't email or PM me Flash questions, that's what the Forums are for! Please don't rely on me reading my PMs either. Email me about important stuff.

 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 randocommando ActionScript 2.0 15 11-04-2009 07:23 PM Meerkat ActionScript 1.0 (and below) 8 08-29-2006 11:39 PM flashmxkid ActionScript 1.0 (and below) 2 09-08-2004 02:30 PM sandyas ActionScript 1.0 (and below) 3 02-14-2004 09:44 AM kerouac9 ActionScript 1.0 (and below) 16 04-18-2002 12:26 PM

All times are GMT. The time now is 06:16 AM.

///