Login
|
Signup
langref.org
-
python
,
clojure
,
cpp
, and
erlang
add..
all
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
Right Space pad a number
Given the number 1024 right pad it to 6 characters
"1024 "
python
"%-6s" % 1024
"%-6s" % 1024
python
str(1024).rjust(6)
str(1024).rjust(6)
python
2.6 or later
'{0: <6}'.format(1024)
'{0: <6}'.format(1024)
clojure
(let [s (str 1024)
l (count s)]
(str s (reduce str (repeat (- 6 l) " "))))
(let [s (str 1024)
l (count s)]
(str s (reduce str (repeat (- 6 l) " "))))
cpp
C++/CLI .NET 2.0
String^ formatted = Convert::ToString(1024)->PadRight(6);
using namespace System;
int main()
{
String^ formatted = Convert::ToString(1024)->PadRight(6);
}
cpp
C++/CLI .NET 2.0
String^ formatted = String::Format("{0,-6:D}", 1024);
using namespace System;
int main()
{
String^ formatted = String::Format("{0,-6:D}", 1024);
}
cpp
std::printf("%-6d\n", 1024);
#include <cstdio>
int main()
{
std::printf("%-6d\n", 1024);
}
cpp
std::ostringstream os;
os << std::setw(6) << std::setfill(' ') << std::left << 1024 << std::ends;
std::cout << os.str() << std::endl;
#include <iostream>
#include <iomanip>
#include <sstream>
int main()
{
std::ostringstream os;
os << std::setw(6) << std::setfill(' ') << std::left << 1024 << std::ends;
std::cout << os.str() << std::endl;
}
cpp
std::cout << boost::format("%|-6|") % 1024 << std::endl;
#include <iostream>
#include "boost/format.hpp"
int main()
{
std::cout << boost::format("%|-6|") % 1024 << std::endl;
}
erlang
Formatted = io_lib:format("~-6B", [1024]),
-module(rightspace).
-export([start/0]).
start() ->
Formatted = io_lib:format("~-6B", [1024]),
io:format("~s~n", [Formatted]).
erlang
io:format("~-6B~n", [1024]).
-module(rightspace).
-export([start/0]).
start() ->
io:format("~-6B~n", [1024]).
Submit a new solution for
python
,
clojure
,
cpp
, or
erlang
There are 21 other solutions in
additional
languages (
csharp
,
fantom
,
fsharp
,
go
...)