Today someone ask me in msn that how to round digit of number for only 2 digit such as 3.15624 to be 3.17

I recommended him to multiple by 100 and round it by function Math.round() and then divide by 100 again.

So I can write function for round digit as here.

Number.prototype.roundDigit(index) {

var index = Math.pow(10,index);

return Math.round(this * index) / index;



num = 10.1245;

trace(num.roundDigit(3)); // display 10.125

or class

Digit = function (num) {
this.num = num;

Digit.prototype.display = function(index) {
var index = Math.pow(10,index);

return Math.round(this.num * index) / index;

// Usage:

myDigit = new Digit(10.1245).display(3);
trace(myScore); // display 10.125


I found this code in a board and I think that it will be useful for making game. Code is about add zero too number.

Number.prototype.addZeros = function(p) {
return new Array(p - length(this) + 1).join('0') + this;

// Usage:
points = 200;

or as a class:

Score = function (points) {
this.points = points;

Score.prototype.display = function(p) {
return new Array(p - length(this.points) + 1).join('0') + this.points;

// Usage:

myScore = new Score(200).display(10);

Note-16-04-06 I just check for this script and it can use in old version. If you try to join by zero and trace for result, you will see "undefined" insert between zero number. So you have to remove "undefined" out.


When dynamic text is rotated by manual or script, it will can't show, but we can solve this problem by "embed font".

กรณีที่ dynamic text มีปัญหาไม่สามารถแสดงข้อความได้เมื่อถูก rotate เรสามารถแก้ปัญหาได้โดยการ embed font ซึ่งจะสามารถแสดงข้อความได้เป็นปกติ