Login
|
Signup
langref.org
-
scala
and
java
add..
all
clojure
cpp
csharp
erlang
fantom
fsharp
go
groovy
haskell
ocaml
perl
php
python
ruby
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
scala
val formatted = String.format("%3.2f", double2Double(7./8.))
object SolutionXX extends Application {
val formatted = String.format("%3.2f", double2Double(7./8.))
println(formatted)
}
scala
printf("%3.2f\n", 7./8.)
object SolutionXX extends Application {
printf("%3.2f\n", 7./8.)
}
java
1.5 or later
String formatted = String.format("%3.2f", 7./8.);
public class SolutionXX {
public static void main(String[] args) {
String formatted = String.format("%3.2f", 7./8.);
System.out.println(formatted);
}
}
Submit a new solution for
scala
or
java
There are 28 other solutions in
additional
languages (
clojure
,
cpp
,
csharp
,
erlang
...)