Login
|
Signup
langref.org
-
php
,
erlang
,
csharp
, and
fantom
add..
all
clojure
cpp
fsharp
go
groovy
haskell
java
ocaml
perl
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
php
printf("%.2g", 7/8);
<?php
printf("%.2g", 7/8);
?>
php
echo round(7/8, 2);
<?php
echo round(7/8, 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]).
csharp
public class FormatDecimal {
public static void Main() {
decimal result = decimal.Round( 7 / 8m, 2);
System.Console.WriteLine(result);
}
}
public class FormatDecimal {
public static void Main() {
decimal result = decimal.Round( 7 / 8m, 2);
System.Console.WriteLine(result);
}
}
fantom
formatted := (7.0/8.0).toLocale("0.00")
class SolutionXX
{
Void main()
{
formatted := (7.0/8.0).toLocale("0.00")
}
}
Submit a new solution for
php
,
erlang
,
csharp
, or
fantom
There are 25 other solutions in
additional
languages (
clojure
,
cpp
,
fsharp
,
go
...)