PDA

Click to See Complete Forum and Search --> : Calculator & Decimal Place Help Needed Please

Jason7178
05-08-2002, 03:50 PM
Hi,
I am building a calculator for a presentation, that will need to have a "," in the thousands place, and fill out to 2 decimal places. I have gotten the two decimal places thing worked out except for the fact that when the answer comes out to be , lets say 2.5, the display field shows 2.5.00. The basic layout of the calc is in levels. Level 1 input text + 25 * .0025 = whatever. There are 10 levels, and at the end, I have another field that dynamically shows each levels answers added together. I will put my code at the bottom of this message, Don't laugh at me, I honestly don't know what I am doing, but have been searching through the boards peicing together information, so I am quite proud that I have any functionality at all. Please help. I still need to figure out how to fix the coma issue, and the extra .00 when the decimal ends up with .5

on (release) {
nextFrame ();
myMulti = (parseFloat(TextField1)*25*.0025);
myMulti2 = (parseFloat(TextField2)*25*.0025);
myMulti3 = (parseFloat(TextField3)*25*.0025);
myMulti4 = (parseFloat(TextField4)*25*.0025);
myMulti5 = (parseFloat(TextField5)*25*.0025);
myMulti6 = (parseFloat(TextField6)*25*.0025);
myMulti7 = (parseFloat(TextField7)*25*.0025);
myMulti8 = (parseFloat(TextField8)*25*.0025);
myMulti9 = (parseFloat(TextField9)*25*.01);
myMulti10 = (parseFloat(TextField10)*25*.05);
DisplayField1 = Math.round(myMulti*100)/100;
DisplayField2 = Math.round(myMulti2*100)/100;
DisplayField3 = Math.round(myMulti3*100)/100;
DisplayField4 = Math.round(myMulti4*100)/100;
DisplayField5 = Math.round(myMulti5*100)/100;
DisplayField6 = Math.round(myMulti6*100)/100;
DisplayField7 = Math.round(myMulti7*100)/100;
DisplayField8 = Math.round(myMulti8*100)/100;
DisplayField9 = Math.round(myMulti9*100)/100;
DisplayField10 = Math.round(myMulti10*100)/100;
myMulti11 = (parseFloat(DisplayField1)+(DisplayField2)+(Displa yField3)+(DisplayField4)+(DisplayField5)+(DisplayF ield6)+(DisplayField7)+(DisplayField8)+(DisplayFie ld9)+(DisplayField10));
DisplayField11 = Math.round(myMulti11*100)/100;
if (myMulti10*10 == Math.round(myMulti10*10)) {
DisplayField10 = myMulti10+".00";
}
if (myMulti9*10 == Math.round(myMulti9*10)) {
DisplayField9 = myMulti9+".00";
}
if (myMulti8*10 == Math.round(myMulti8*10)) {
DisplayField8 = myMulti8+".00";
}
if (myMulti7*10 == Math.round(myMulti7*10)) {
DisplayField7 = myMulti7+".00";
}
if (myMulti6*10 == Math.round(myMulti6*10)) {
DisplayField6 = myMulti6+".00";
}
if (myMulti5*10 == Math.round(myMulti5*10)) {
DisplayField5 = myMulti5+".00";
}
if (myMulti4*10 == Math.round(myMulti4*10)) {
DisplayField4 = myMulti4+".00";
}
if (myMulti3*10 == Math.round(myMulti3*10)) {
DisplayField3 = myMulti3+".00";
}
if (myMulti2*10 == Math.round(myMulti2*10)) {
DisplayField2 = myMulti2+".00";
}
if (myMulti*10 == Math.round(myMulti*10)) {
DisplayField1 = myMulti+".00";
}
}

Thanks so much for your help.
Flashkit is awesome.

Jason Simpson

Jason7178
05-08-2002, 09:45 PM
Hi,
I am building a calculator for a presentation, that will need to have a "," in the thousands place, and fill out to 2 decimal places. I have gotten the two decimal places thing worked out except for the fact that when the answer comes out to be , lets say 2.5, the display field shows 2.5.00. The basic layout of the calc is in levels. Level 1 input text + 25 * .0025 = whatever. There are 10 levels, and at the end, I have another field that dynamically shows each levels answers added together. I will put my code at the bottom of this message, Don't laugh at me, I honestly don't know what I am doing, but have been searching through the boards peicing together information, so I am quite proud that I have any functionality at all. Please help. I still need to figure out how to fix the coma issue, and the extra .00 when the decimal ends up with .5

on (release) {
nextFrame ();
myMulti = (parseFloat(TextField1)*25*.0025);
myMulti2 = (parseFloat(TextField2)*25*.0025);
myMulti3 = (parseFloat(TextField3)*25*.0025);
myMulti4 = (parseFloat(TextField4)*25*.0025);
myMulti5 = (parseFloat(TextField5)*25*.0025);
myMulti6 = (parseFloat(TextField6)*25*.0025);
myMulti7 = (parseFloat(TextField7)*25*.0025);
myMulti8 = (parseFloat(TextField8)*25*.0025);
myMulti9 = (parseFloat(TextField9)*25*.01);
myMulti10 = (parseFloat(TextField10)*25*.05);
DisplayField1 = Math.round(myMulti*100)/100;
DisplayField2 = Math.round(myMulti2*100)/100;
DisplayField3 = Math.round(myMulti3*100)/100;
DisplayField4 = Math.round(myMulti4*100)/100;
DisplayField5 = Math.round(myMulti5*100)/100;
DisplayField6 = Math.round(myMulti6*100)/100;
DisplayField7 = Math.round(myMulti7*100)/100;
DisplayField8 = Math.round(myMulti8*100)/100;
DisplayField9 = Math.round(myMulti9*100)/100;
DisplayField10 = Math.round(myMulti10*100)/100;
myMulti11 = (parseFloat(DisplayField1)+(DisplayField2)+(Displa yField3)+(DisplayField4)+(DisplayField5)+(DisplayF ield6)+(DisplayField7)+(DisplayField8)+(DisplayFie ld9)+(DisplayField10));
DisplayField11 = Math.round(myMulti11*100)/100;
if (myMulti10*10 == Math.round(myMulti10*10)) {
DisplayField10 = myMulti10+".00";
}
if (myMulti9*10 == Math.round(myMulti9*10)) {
DisplayField9 = myMulti9+".00";
}
if (myMulti8*10 == Math.round(myMulti8*10)) {
DisplayField8 = myMulti8+".00";
}
if (myMulti7*10 == Math.round(myMulti7*10)) {
DisplayField7 = myMulti7+".00";
}
if (myMulti6*10 == Math.round(myMulti6*10)) {
DisplayField6 = myMulti6+".00";
}
if (myMulti5*10 == Math.round(myMulti5*10)) {
DisplayField5 = myMulti5+".00";
}
if (myMulti4*10 == Math.round(myMulti4*10)) {
DisplayField4 = myMulti4+".00";
}
if (myMulti3*10 == Math.round(myMulti3*10)) {
DisplayField3 = myMulti3+".00";
}
if (myMulti2*10 == Math.round(myMulti2*10)) {
DisplayField2 = myMulti2+".00";
}
if (myMulti*10 == Math.round(myMulti*10)) {
DisplayField1 = myMulti+".00";
}
}

Thanks so much for your help.
Flashkit is awesome.

Jason Simpson

Ed Mack
05-09-2002, 06:08 PM

moises
05-10-2002, 04:41 AM

// You enter a number and the number of decimals you want
//for that number, in case that number has decimals:

function NumberDecimals (number, decimals) {
var number_str = new String(number);
var index = number_str.indexOf(".");
var outcome = number_str.substring(0, index+decimals+1);
return outcome;
}

Example:

numberWithTwoDecimals=NumberDecimals (58.12365, 2);

Then numberWithTwoDecimals = 58.12

:)

Ed Mack
05-10-2002, 08:19 PM
Here's one:

To 2 dcp:
function dec(n){
dec *= 100;
dec = int(dec);
dec /= 100;
return dec;
}

To d dcp:
function dec(n,d){
dec *= Math.pow(10,d);
dec = int(dec);
dec /= Math.pow(10,d);
return dec;
}