Login
|
Signup
langref.org
-
python
,
fsharp
,
fantom
,
groovy
...
add..
all
clojure
cpp
csharp
erlang
go
java
ocaml
perl
php
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
python
"%.2f" % (7 / 8.0)
"%.2f" % (7 / 8.0)
python
round(7./8., 2)
round(7./8., 2)
fsharp
printfn "%3.2f" (0.7 / 0.8)
#light
open System
printfn "%3.2f" (0.7 / 0.8)
fsharp
let formatted = String.Format("{0,3:F2}", (0.7 / 0.8))
Console.WriteLine(formatted)
#light
open System
let formatted = String.Format("{0,3:F2}", (0.7 / 0.8))
Console.WriteLine(formatted)
fantom
formatted := (7.0/8.0).toLocale("0.00")
class SolutionXX
{
Void main()
{
formatted := (7.0/8.0).toLocale("0.00")
}
}
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)
haskell
import Text.Printf
printf "%3.2f" (7/8)
import Text.Printf
printf "%3.2f" (7/8)
haskell
main = putStrLn $ Numeric.showFFloat (Just 2) (7/8) ""
main = putStrLn $ Numeric.showFFloat (Just 2) (7/8) ""
Submit a new solution for
python
,
fsharp
,
fantom
,
groovy
...
There are 21 other solutions in
additional
languages (
clojure
,
cpp
,
csharp
,
erlang
...)