View Problem

Format a decimal number

Format the number 7/8 as a decimal with 2 places: 0.88
DiskEdit
python
"%.2f" % (7 / 8.0)
DiskEdit
python
round(7./8., 2)
ExpandDiskEdit
cpp C++/CLI .NET 2.0
String^ formatted = String::Format("{0,3:F2}", result);
ExpandDiskEdit
cpp C++/CLI .NET 2.0
Console::WriteLine("{0,3:F2}", (7. / 8.));
ExpandDiskEdit
cpp
std::printf("%3.2f\n", result);
ExpandDiskEdit
cpp
std::ostringstream os;
os.width(3); os.fill('0'); os.setf(std::ios::fixed|std::ios::showpoint); os.precision(2);
os << result << std::ends;
std::cout << os.str() << std::endl;
ExpandDiskEdit
cpp
std::cout << boost::format("%|3.2f|") % result << std::endl;
ExpandDiskEdit
erlang
Formatted = io_lib:format("~.2f", [7/8]),
ExpandDiskEdit
erlang
io:format("~.2f~n", [7/8]).

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