View Problem

Format a decimal number

Format the number 7/8 as a decimal with 2 places: 0.88
ExpandDiskEdit
php
printf("%.2g", 7/8);
ExpandDiskEdit
php
echo round(7/8, 2);
ExpandDiskEdit
erlang
Formatted = io_lib:format("~.2f", [7/8]),
ExpandDiskEdit
erlang
io:format("~.2f~n", [7/8]).
DiskEdit
csharp
public class FormatDecimal {
public static void Main() {
decimal result = decimal.Round( 7 / 8m, 2);
System.Console.WriteLine(result);
}
}
ExpandDiskEdit
fantom
formatted := (7.0/8.0).toLocale("0.00")

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