View Problem

Zero pad a number

Given the number 42, pad it to 8 characters like 00000042
DiskEdit
python
"%08d" % 42
ExpandDiskEdit
fsharp
printfn "%08d" 42
ExpandDiskEdit
fsharp
let formatted = sprintf "%08d" 42
printfn "%s" formatted
ExpandDiskEdit
fsharp
let buffer = new StringBuilder()
Printf.bprintf buffer "%08d" 42
printfn "%s" (buffer.ToString())
ExpandDiskEdit
fsharp
let formatted = String.Format("{0,8:D8}", 42)
Console.WriteLine(formatted)
ExpandDiskEdit
fsharp
let formatted = Convert.ToString(42).PadLeft(8, '0')
Console.WriteLine(formatted)
ExpandDiskEdit
fantom
formatted := 42.toStr.padl(8, '0')
ExpandDiskEdit
fantom
formatted := 42.toLocale("00000000")
ExpandDiskEdit
groovy
formatted = new DecimalFormat('00000000').format(42)
ExpandDiskEdit
groovy
formatted = 42.toString().padLeft(8, '0')
ExpandDiskEdit
groovy
// to stdout
printf "%08d\n", 42
// to a string
formatted = sprintf("%08d", 42)
ExpandDiskEdit
groovy
formatted = String.format("%08d", 42)
DiskEdit
haskell
import Text.Printf

printf "%08d" 42

Submit a new solution for python, fsharp, fantom, groovy ...
There are 24 other solutions in additional languages (clojure, cpp, csharp, erlang ...)