Click to See Complete Forum and Search --> : [RESOLVED] Scientific notation?
manuel-jrs
07-20-2008, 01:59 PM
Hi, I have a problem, I am designing a Coulomb Law's simulation in KoolMoves but I work with small and big numbers for example 0.0000001656 or 1212121212.1235, I need to convert that in scientific notation (1.656e-7 or 1.212e+10), Can you help me? please...
this is importat for me, help me please... thanks... :confused:
necromanthus
07-20-2008, 06:23 PM
Create a single keyframe movie, insert a dynamic text field (txt1) in that frame and set this script in the main timeline:
n = "0.0000001656";
txt1.text = Number(n);
stop();
Tell us the result.
:cap:
manuel-jrs
07-20-2008, 10:52 PM
Thanks necromanthus, but if I have a 3 dynamic text, a button and a single keyframe movie, and in this button I do math operations with the 3 dynamic text (for example txt1*txt2*txt3=txt4)and I want to send the results to another dynamic text(for exaple txt4) but send it with the scientific notation and use only 3 decimals, for example "1.234e+5".... this is possible? Thanks!
blanius
07-21-2008, 08:48 AM
I believe his point is that you should force flash to convert the text to numbers first.
txt4.text=Number(txt1.text)+Number(txt2.text)+Numb er(txt3.text)
should do what you want.
manuel-jrs
07-24-2008, 06:56 PM
Hi, I use this and I got a good results... Thanks...
function formatDecimals(num, digits) {
if (digits <= 0) {
return Math.round(num);
}
var tenToPower = Math.pow(10, digits);
var cropped = String(Math.round(num * tenToPower) / tenToPower);
if (cropped.indexOf(".") == -1) {
cropped += ".0";
}
var halves = cropped.split(".");
var zerosNeeded = digits - halves[1].length;
for (var i=1; i <= zerosNeeded; i++) {
cropped += "0";
}
return(cropped);
}
function toScientific(num, sigDigs) {
num = Number(num);
if (isNaN(num)) return num;
var exponent = Math.floor(Math.log(Math.abs(num)) / Math.LN10);
if (num == 0) exponent = 0;
var tenToPower = Math.pow(10, exponent);
var mantissa = num / tenToPower;
mantissa = formatDecimals(mantissa, sigDigs-1);
var output = mantissa;
if (exponent != 0) {
output += "e" + exponent;
}
return(output);
} :cap:
manuel-jrs
07-24-2008, 07:14 PM
[resolved]
blanius
07-24-2008, 07:34 PM
That's great but I really don't think you needed to do all that. When I tried it with just forcing the conversion to number it should in in scientific notation.
flashkit.com
Copyright WebMediaBrands Inc., All Rights Reserved.