Login
|
Signup
langref.org
-
groovy
and
erlang
add..
all
clojure
cpp
csharp
fantom
fsharp
go
haskell
java
ocaml
perl
php
python
ruby
scala
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Numbers
Output
Format a decimal number
Format the number 7/8 as a decimal with 2 places: 0.88
groovy
def result = 7/8
println result.round(new MathContext(2))
import java.math.*
def result = 7/8
println result.round(new MathContext(2))
groovy
def result = 7/8
printf "%.2g", result
// run on Java 1.5+
def result = 7/8
printf "%.2g", result
groovy
1.6.4
new Double(7/8).round(2)
new Double(7/8).round(2)
erlang
Formatted = io_lib:format("~.2f", [7/8]),
-module(decfmt).
-export([start/0]).
start() ->
Formatted = io_lib:format("~.2f", [7/8]),
io:format("~s~n", [Formatted]).
erlang
io:format("~.2f~n", [7/8]).
-module(decfmt).
-export([start/0]).
start() ->
io:format("~.2f~n", [7/8]).
Submit a new solution for
groovy
or
erlang
There are 26 other solutions in
additional
languages (
clojure
,
cpp
,
csharp
,
fantom
...)