String formatted = new DecimalFormat("00000000").format(42);
import java.text.DecimalFormat;
public class Solution33 { public static void main(String[] args) { String formatted = new DecimalFormat("00000000").format(42); System.out.println(formatted); } }
java1.5 or later
String formatted = String.format("%08d", 42);
public class Solution382 { public static void main(String[] args) { String formatted = String.format("%08d", 42); System.out.println(formatted); } }
ocaml
Printf.printf "%08d" 42;;
Printf.printf "%08d" 42;;
ocaml
let s = Printf.sprintf "%08d" 42 in print_string s;;
let s = Printf.sprintf "%08d" 42 in print_string s;;
perl
sprintf("%08d", 42);
sprintf("%08d", 42);
php
echo str_pad(42, 8, 0, STR_PAD_LEFT);
<?php echo str_pad(42, 8, 0, STR_PAD_LEFT); ?>
php
printf("%08d", 42);
<?php printf("%08d", 42); ?>
python
"%08d" % 42
"%08d" % 42
ruby
42.to_s.rjust(8,"0")
42.to_s.rjust(8,"0")
ruby
"%08d" % 42
"%08d" % 42
scala
val formatted = String.format("%08d", int2Integer(42))
object SolutionXX extends Application {
val formatted = String.format("%08d", int2Integer(42))