Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-20-2012, 03:38 AM   #1
kadin
Registered User
 
Join Date: Mar 2012
Posts: 29
Default 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.
kadin is offline   Reply With Quote
Old 03-20-2012, 03:42 AM   #2
kadin
Registered User
 
Join Date: Mar 2012
Posts: 29
Default

I may have discovered the answer. Multiply .9142857 * 100= 91.42 and then round.
kadin is offline   Reply With Quote
Old 03-20-2012, 03:44 AM   #3
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,403
Default

ActionScript Code:
var num:Number = 128/140 * 100; trace(num); trace(Math.floor(num));
[afz]snickelfitz is offline   Reply With Quote
Old 03-20-2012, 10:58 AM   #4
SephirothOWA
Senior Member
 
Join Date: Jun 2010
Location: Ipswich, England
Posts: 260
Default

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
SephirothOWA is offline   Reply With Quote
Old 03-20-2012, 11:24 AM   #5
poltuda
Senior Member
 
Join Date: May 2010
Posts: 253
Default

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.
poltuda is offline   Reply With Quote
Old 03-20-2012, 05:35 PM   #6
abeall
Senior Member
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,812
Send a message via AIM to abeall
Default

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
abeall is offline   Reply With Quote
Old 03-20-2012, 06:00 PM   #7
lordofduct
Senior Member
 
lordofduct's Avatar
 
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 3,872
Default

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!
lordofduct is offline   Reply With Quote
Old 03-20-2012, 06:02 PM   #8
abeall
Senior Member
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,812
Send a message via AIM to abeall
Default

Sure, and lets see how much more discussion we can have without evening discussing the problem!
__________________
Aaron Beall | Flash portfolio | Fireworks extensions | Twitter
abeall is offline   Reply With Quote
Old 03-20-2012, 06:05 PM   #9
Barna Biro
Senior Member
 
Barna Biro's Avatar
 
Join Date: Nov 2009
Location: LU, Switzerland
Posts: 1,410
Default

Quote:
Originally Posted by lordofduct View Post
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.
Barna Biro 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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:35 AM.

///
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.