View Problem

Format a decimal number

Format the number 7/8 as a decimal with 2 places: 0.88
DiskEdit
ruby
(7.0/8.0*100).round/100.0
DiskEdit
ruby 1.9+
(7.0/8.0).round(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
fsharp
printfn "%3.2f" (0.7 / 0.8)
ExpandDiskEdit
fsharp
let formatted = String.Format("{0,3:F2}", (0.7 / 0.8))
Console.WriteLine(formatted)

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