Login
|
Signup
langref.org
-
python
,
clojure
, and
erlang
add..
all
cpp
csharp
fantom
fsharp
go
groovy
haskell
java
ocaml
perl
php
ruby
scala
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Numbers
Output
Zero pad a number
Given the number 42, pad it to 8 characters like 00000042
python
"%08d" % 42
"%08d" % 42
clojure
clojure
(defn pad
([x] (if (> 8 (.length (str x))) (pad (str 0 x)) (str x)))
)
(defn pad
([x] (if (> 8 (.length (str x))) (pad (str 0 x)) (str x)))
)
clojure
clojure
(defn pad [x]
(format "%08d" x))
(defn pad [x]
(format "%08d" x))
clojure
(format "%08d" 42)
(format "%08d" 42)
erlang
Formatted = io_lib:format("~8..0B", [42]),
-module(zeropad).
-export([start/0]).
start() ->
Formatted = io_lib:format("~8..0B", [42]),
io:format("~s~n", [Formatted]).
erlang
io:format("~8..0B~n", [42]).
-module(zeropad).
-export([start/0]).
start() ->
io:format("~8..0B~n", [42]).
Submit a new solution for
python
,
clojure
, or
erlang
There are 31 other solutions in
additional
languages (
cpp
,
csharp
,
fantom
,
fsharp
...)