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;

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