Home Tutorials Forums Articles Blogs Movies Library Employment Press

 ActionScript.org Forums How to convert 0.9142857 to just 91
 Register FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

 03-20-2012, 03:38 AM #1 kadin Registered User   Join Date: Mar 2012 Posts: 29 How to convert 0.9142857 to just 91 If I divide a number like 128/140= 0.9142857 or 91%. I am trying to get just 91. I don't think these will work. Am I wrong? Thanks. round() Rounds the value of the parameter val up or down to the nearest integer and returns the value. If val is equidistant from its two nearest integers (that is, if the number ends in .5), the value is rounded up to the next higher integer. ceil() Returns the ceiling of the specified number or expression. The ceiling of a number is the closest integer that is greater than or equal to the number. abs() Computes and returns an absolute value for the number specified by the parameter val.
 03-20-2012, 03:42 AM #2 kadin Registered User   Join Date: Mar 2012 Posts: 29 I may have discovered the answer. Multiply .9142857 * 100= 91.42 and then round.
 03-20-2012, 03:44 AM #3 [afz]snickelfitz Senior Member     Join Date: Dec 2011 Location: Tucson, AZ Posts: 2,411 ActionScript Code: ```var num:Number = 128/140 * 100; trace(num); trace(Math.floor(num));```
 03-20-2012, 10:58 AM #4 SephirothOWA Senior Member   Join Date: Jun 2010 Location: Ipswich, England Posts: 263 Doing: ActionScript Code: `var num:int = (128 / 140) * 100` would give you the whole integer value 91, whethe rit be 91.4, or 91.7
 03-20-2012, 11:24 AM #5 poltuda Senior Member   Join Date: May 2010 Posts: 253 ActionScript Code: ```var num:Number = 128/140*100; trace(num); trace(Math.floor(num)); var num1:Number = 0.9142857*100; trace(Math.abs(num1).toFixed(2));``` poltuda Last edited by poltuda; 03-20-2012 at 11:27 AM.
 03-20-2012, 05:35 PM #6 abeall Senior Member   Join Date: Feb 2006 Location: Washington, DC Posts: 2,812 You could also just do this: ActionScript Code: `num = Number(num.toFixed(2)); // trims number to 2 decimal places ` If you want to actually round to 2 decimal places you can try: ActionScript Code: ```function roundNumToLength(number:Number, decimalPlaces:Number):Number {     var decimal:Number = Math.pow(10, decimalPlaces);     return Math.round(number * decimal) / decimal; } // example: roundNumToLength(0.941) // returns 0.94 roundNumToLength(0.949) // returns 0.95 ``` __________________ Aaron Beall | Flash portfolio | Fireworks extensions | Twitter
 03-20-2012, 06:00 PM #7 lordofduct Senior Member     Join Date: Feb 2008 Location: West Palm Beach, FL Posts: 3,872 srsly, this much discussion over formatting a percentage value in a topic where OP figured out the answer for themselves? __________________ www.lordofduct.com - come read my blog! If you want to know how to program, take a math class, take a lot of math classes!
 03-20-2012, 06:02 PM #8 abeall Senior Member   Join Date: Feb 2006 Location: Washington, DC Posts: 2,812 Sure, and lets see how much more discussion we can have without evening discussing the problem! __________________ Aaron Beall | Flash portfolio | Fireworks extensions | Twitter
03-20-2012, 06:05 PM   #9
Barna Biro
Senior Member

Join Date: Nov 2009
Location: LU, Switzerland
Posts: 1,410

Quote:
 Originally Posted by lordofduct srsly, this much discussion over formatting a percentage value in a topic where OP figured out the answer for themselves?
Haha, I was thinking th same thing
This little question really spawned a long thread...
__________________
Titus M. Plautus - Not by age but by capacity is wisdom acquired.

 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 On 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

All times are GMT. The time now is 11:53 PM.

///