Hi! Tell me how to add zeros in front of a digit up to 10?
This demo: [https://codepen.io/ethereal94/pen/gOaQbxm](https://codepen.io/ethereal94/pen/gOaQbxm)
Thanks!
padStart(length, str)
``<i> </i>"1".padStart(10, "0");<i> </i>`</CODE> Or, making use of your code: <CODE>`<i> </i>$('.box .number').each(function(i,elem) { $(elem).text((i+1).toString().padStart(10, "0")); });<i> </i>``
<i> </i>"1".padStart(10, "0");<i> </i>
</CODE> Or, making use of your code: <CODE>
<i> </i>$('.box .number').each(function(i,elem) { $(elem).text((i+1).toString().padStart(10, "0")); });<i> </i>
padStart(10, "0"))
padStart(2, "0"))
``<i> </i> import java.util.Scanner; class Example { public static void main(String args[]) { String givenNumber; int zeroCount; Scanner sc = new Scanner(System.in); System.out.println("Enter a number : "); givenNumber = sc.next(); System.out.println("Enter total numbers of zeros : "); zeroCount = sc.nextInt(); String formatter = "%0" + (givenNumber.length() + zeroCount) + "d"; System.out.println("Final number : " + String.format(formatter, Integer.valueOf(givenNumber))); } }<i> </i>``
<i> </i> import java.util.Scanner; class Example { public static void main(String args[]) { String givenNumber; int zeroCount; Scanner sc = new Scanner(System.in); System.out.println("Enter a number : "); givenNumber = sc.next(); System.out.println("Enter total numbers of zeros : "); zeroCount = sc.nextInt(); String formatter = "%0" + (givenNumber.length() + zeroCount) + "d"; System.out.println("Final number : " + String.format(formatter, Integer.valueOf(givenNumber))); } }<i> </i>
$('.box .number').each(function(i,elem) {<br/> let resultat = ++i;<br/> $(elem).text(resultat <10 ? '0${resultat}' : resultat);<br/> });
> Replace just the ' by ` I can't do it here
Help @ethereal spread the word by sharing this article on Twitter...