E
E
Edwin Petrovich2019-03-02 00:41:13
ActionScript
Edwin Petrovich, 2019-03-02 00:41:13

How to add a zero before a number in ActionScript 3.0?

Greetings!
Need help. How to set a condition in Action Script 3.0: if the number is less than ten, then add zero to it in front?
var date:Date = new Date();
varday = date.getDate();
if (day ???????) {day = "0" + day;}
trace (day);
Those. how to add - there is no question, here is the working code: {day = "0" + day;}
It is not clear how to make the listener understand that the number of the day, for example, 2nd, is less than ten and add zero to it in front - "02" ?
In AS 2.0, this LENGTH parameter works fine (i.e. it gives "01", "02", etc. instead of "1", "2", etc.):
onClipEvent(enterFrame)
{
day = clipDate .getDate(); // Set the Variable of the day!
if (length (day) == 1) {day = "0" + day;} // If the number is less than ten, then + 0 to it!
trace(day);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
illuzor, 2019-03-02
@iLLuzor

As3 has strong typing. Everything works in as2 because of dynamic typing.
First, date.getDate() returns a Number;
Second, you need a separate String variable for your value.
Thirdly, the condition is the simplest - if (day > 9)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question