Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-23-2002, 10:44 PM   #1
Registered User
Join Date: May 2002
Location: -
Posts: 19
Send a message via AIM to rcr639
Default 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
rcr639 is offline   Reply With Quote
Old 05-23-2002, 10:55 PM   #2
Join Date: Jun 2001
Location: portland, or
Posts: 8,106

please search
what the hell was i thinking?
tg is offline   Reply With Quote
Old 05-24-2002, 01:31 AM   #3
Registered User
Join Date: May 2002
Location: -
Posts: 19
Send a message via AIM to rcr639

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?
rcr639 is offline   Reply With Quote
Old 05-24-2002, 01:37 AM   #4
Registered User
Join Date: May 2002
Location: -
Posts: 19
Send a message via AIM to rcr639

could this script be incorporated someway so that all calculated numbers round to 2 decimal places

rcr639 is offline   Reply With Quote
Old 05-26-2002, 03:14 AM   #5
ActionScript.org Founder
Jesse's Avatar
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.

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.
Jesse is offline   Reply With Quote

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Keeping answers to two decimal places randocommando ActionScript 2.0 15 11-04-2009 07:23 PM
Decimal places Meerkat ActionScript 1.0 (and below) 8 08-29-2006 11:39 PM
decimal places.... flashmxkid ActionScript 1.0 (and below) 2 09-08-2004 02:30 PM
decimal places sandyas ActionScript 1.0 (and below) 3 02-14-2004 09:44 AM
Showing zeroes as decimal places kerouac9 ActionScript 1.0 (and below) 16 04-18-2002 12:26 PM

All times are GMT. The time now is 11:37 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.