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);
}
}
DiskEdit
clojure
(format "%3.2f" (/ 7.0 8))
DiskEdit
clojure
(* 0.01 (Math/round (* 100 (float (/ 7 8)))))
ExpandDiskEdit
groovy
def result = 7/8
println result.round(new MathContext(2))
ExpandDiskEdit
groovy
def result = 7/8
printf "%.2g", result
DiskEdit
groovy 1.6.4
new Double(7/8).round(2)

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