Home Tutorials Forums Articles Blogs Movies Library Employment Press

<< Prev 5 | Next 5

currency formatter math object

// Improved Currency Formatter
// taking the best to two previous scripts and 
// making it work on decimals, and whole numbers
// Geordie Martinez www.thenewchannel.tv

Math.__proto__.toMoney = function(num) {
	value = String(Math.round(num * 100) / 100); //gets me down to two decimal points
	dot = value.indexOf("."); // does it have cents?
	money = "$"; // type of currency symbol here
	if (dot == -1) {
		value += ".0";
	}
	temp = value.split(".");
	addDecimals = 2 - temp[1].length;
	for (i = 1; i <= addDecimals; i++) {
		value += "0";
	}
	// add commas if it needs it
	chopped = value.split(".");
	frontHalf = chopped[0];
	if (frontHalf.length > 0) {
		myLength = frontHalf.length;
		divide = myLength / 3;
		if ((myLength % 3) == 0) {
			divide = (myLength / 3) - 1;
		}
		for (var i = 1; i <= divide; i++) {
			frontHalf = frontHalf.substr(0, (myLength - (3 * i) - (i - 1))) + "," + frontHalf.substr((myLength - (3 * i) - (i - 1)), (3 * i) + (i - 1));
			myLength = frontHalf.length;
		}
		dollars = frontHalf;
	} else {
		dollars = frontHalf;
	}
	
	return "" + money + dollars + "." + chopped[1];
};

Posted by: Geordie Martinez | website http://www.thenewchannel.tv
Decimal to Hexadecimal conversion (dec to hex)
/*
Decimal to Hexadecimal conversion
Harold Geslain, 2005 (modified from infinitemonkeys)

Description :
This script converts 3 decimal values (from 0 to 255)
to corresponding hexadecimal values. Very useful for
using with the Color object.

*/

function decToHex(frm1, frm2, frm3) {
        var decVal1 = parseInt(frm1);
        var decVal2 = parseInt(frm2);
        var decVal3 = parseInt(frm3);
        if (decVal1 != NaN && decVal2 != NaN && decVal3 != NaN) {
                decVal1 = decVal1.toString(16);
                decVal2 = decVal2.toString(16);
                decVal3 = decVal3.toString(16);
                if (decVal1.length < 2) {
                        decVal1 = '0' + decVal1;
                }
                if (decVal2.length < 2) {
                        decVal2 = '0' + decVal2;
                }
                if (decVal3.length < 2) {
                        decVal3 = '0' + decVal3;
                }
                if (decVal1 != NaN && decVal2 != NaN && decVal3 != NaN) {
                        trace('The Hexadecimal equivalent is : ' + decVal1 + decVal2 + decVal3);
                        return(decVal1 + decVal2 + decVal3);
                } else {
                        trace('Numbers are not from 0 to 255');
                }
        }
}

// To test this script use the following
decToHex(255, 155, 55);

Posted by: Harold Geslain | website http://www.tornademultimedia.com/
Drawing API with MATH
clip_mc = createEmptyMovieClip("clip"+clipDepth,1000-clipDepth++);
clipY = 400-clipDepth*10
clipX = clipDepth
if (clipY<=0){
        delete _root.onEnterFrame;
}
clip_mc._y = clipY;
clip_mc._x = clipX;
clip_mc.lineStyle(1, 0x000000,100);
clip_mc.beginFill(0xFFFFFF,100);
angleX = Math.random()*0.1;
for(i=0; i<70; i++){
        x = i*10;
        y = Math.tan(x)*Math.sin(angleX += .3);
        clip_mc.lineTo(x,y);}
clip_mc.lineTo(x,50);
clip_mc.lineTo(0,50);
clip_mc.lineTo(0,0);
clip_mc.endFill();
}

Posted by: Joel Kirchartz | website http://www.joelkirchartz.com
EXPONENTIAL EASING
///////////// EXPONENTIAL EASING ////////////////////// 
//// Robert Penner - Sept. 2001 - robertpenner.com //// 

// exponential easing in - accelerating from zero velocity
// t: current time, b: beginning value, c: change in position, d: duration
Math.easeInExpo = function (t, b, c, d) {
	var flip = 1;
	if (c < 0) {
		flip *= -1;
		c *= -1;
	}
	return flip * (Math.exp(Math.log(c)/d * t)) + b;
}

// exponential easing out - decelerating to zero velocity
// t: current time, b: beginning value, c: change in position, d: duration
Math.easeOutExpo = function (t, b, c, d) {
	var flip = 1;
	if (c < 0) {
		flip *= -1;
		c *= -1;
	}
	return flip * (-Math.exp(-Math.log(c)/d * (t-d)) + c + 1) + b;
}

// exponential easing in/out - accelerating until halfway, then decelerating
// t: current time, b: beginning value, c: change in position, d: duration
Math.easeInOutExpo = function (t, b, c, d) {
	var flip = 1;
	if (c < 0) {
		flip *= -1;
		c *= -1;
	}
	if (t < d/2) return flip * (Math.exp(Math.log(c/2)/(d/2) * t)) + b;
	return flip * (-Math.exp(-2*Math.log(c/2)/d * (t-d)) + c + 1) + b;
}
This is the most dramatic easing. It's actually the same curve as the classic halfway-every-frame method, but you have to beat it over the head (with a log or two) to bring it under control.
Posted by: Robert Penner | website http://www.robertpenner.com
find sin,cos,tan and there reverse
/*use six buttons and use these action script on every  button*/
 (release) {
var z,k;
z=a;
z=z/57.29577951;    

k=Math.sin ( z );
b=k;
}

on (release) {
	var z, k;
	z = a;
	z = z/57.29577951;
	k = Math.cos(z);
	b = k;
}
on (release) {
	var z, k;
	z = a;
	z = z/57.29577951;
	k = Math.tan(z);
	b = k;
}
on (release) {
	var z, k;
	z = a;
	z = z/57.29577951;
	k = Math.acos(z);
	b = k;
}
on (release) {
	var z, k;
	z = a;
	z = z/57.29577951;
	k = Math.asin(z);
	b = k;
}
on (release) {
	var z, k;
	z = a;
	z = z/57.29577951;
	k = Math.atan(z);
	b = k;
}

Posted by: zeeshan khan | website http://www.ajkashmir.8k.com

<< Prev 5 | Next 5

Copyright 2000-2010 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.