0

I need to format a string so that it looks like:

"Expect 000062" in javascript.

In C# I do this:

String expect = String.Format("Expect {0:000000}", data.Length);

In Swift I do this:

var expect = NSString(format: "Expect %06d", data.length)

How do I do this same thing in javascript?

Andrew
  • 521
  • 7
  • 18
  • 1
    possible duplicate of [How can I create a Zerofilled value using JavaScript?](http://stackoverflow.com/questions/1267283/how-can-i-create-a-zerofilled-value-using-javascript) – Politank-Z May 20 '15 at 16:49

1 Answers1

0

Try something like this:

var Num = "64";
var nNum = ("000000" + Num).slice(-6);
console.log(nNum);
Zee
  • 8,420
  • 5
  • 36
  • 58