# `Round`

``Round( value, [ precision ]  )``
``Round( value, [ precision ]  )``
``Round( value, [ precision ]  )``
``Round( value, [ precision ]  )``
``round( value, [ precision ]  )``
``Round( value, [ precision ]  )``

## Description

The `Round` function returns a number which is the nearest mathematic value of the operand to the specified precision as a double value.

## Parameters

Parameter Type Definition and Requirements

`value`

A Number to be rounded with a specific precision.

`precision`

Optional - Defines how many digits to the right or left of the decimal place should be returned. The default precision is 2 which returns up to the hundredths decimal places. A positive precision specifies digits to the right of the decimal point. A negative precision specifies digits to the left of the decimal point. A zero precision rounds the fractional part of the number.

Since Go does not have function overloading or optional arguments, you must use the function `f.Precision()` instead of a plain number.

## Returns

A Number with its precision modified.

## Examples

The following query executes an array of independent rounding operations and returns the results in an array. The result array position matches the position of the execution array position. The first operation takes the value 1234.5678 and by default rounds the value to 2 digits to the right of the decimal point. The result is 1234.57 which is in the top position of the result array. The second operation rounds the value 1234 to a precision of -2. This is two digits to the left of the decimal point, the hundreds position. The operations to the left of the decimal point are zero filled less than the specified precision. The result of 1200 is placed in the third position of the result array.

``````try
{
Value result = await client.Query(
Arr(
Round(1234.5678),
Round(1234, -2),
Round(1234.5678, 2),
Round(1234.5678, -2),
Round(5678.1234, 3),
Round(1234, -3),
Round(5678.1234, -3)
)
);

Console.WriteLine(result);
}
catch (Exception e)
{
Console.WriteLine(\$"ERROR: {e.Message}");
}``````
``Arr(DoubleV(1234.57), LongV(1200), DoubleV(1234.57), DoubleV(1200), DoubleV(5678.123), LongV(1000), DoubleV(6000))``
``````result, err := client.Query(
f.Arr{
f.Round(1234.5678),
f.Round(1234, f.Precision(-2)),
f.Round(1234.5678, f.Precision(2)),
f.Round(1234.5678, f.Precision(-2)),
f.Round(5678.1234, f.Precision(3)),
f.Round(1234, f.Precision(-3)),
f.Round(5678.1234, f.Precision(-3)),
})

if err != nil {
fmt.Fprintln(os.Stderr, err)
} else {
fmt.Println(result)
}``````
``[1234.57 1200 1234.57 1200 5678.123 1000 6000]``
``````System.out.println(
client.query(
Arr(
Round(1234.5678),
Round(1234L, -2L),
Round(1234.5678, 2L),
Round(1234.5678, -2L),
Round(5678.1234, 3L),
Round(1234L, -3L),
Round(5678.1234, -3L)
)
).get());``````
``[1234.57, 1200, 1234.57, 1200.0, 5678.123, 1000, 6000.0]``
``````client.query(
[
q.Round(1234.5678),
q.Round(1234, -2),
q.Round(1234.5678, 2),
q.Round(1234.5678, -2),
q.Round(5678.1234, 3),
q.Round(1234, -3),
q.Round(5678.1234, -3),
]
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
'Error: [%s] %s: %s',
err.name,
err.message,
err.errors()[0].description,
))``````
``````[
1234.57, 1200,
1234.57, 1200,
5678.123, 1000,
6000
]``````
``````result = client.query(
[
q.round(1234.5678),
q.round(1234, -2),
q.round(1234.5678, 2),
q.round(1234.5678, -2),
q.round(5678.1234, 3),
q.round(1234, -3),
q.round(5678.1234, -3)
]
)
print(result)``````
``[1234.57, 1200, 1234.57, 1200.0, 5678.123, 1000, 6000.0]``
``````[
Round(1234.5678),
Round(1234, -2),
Round(1234.5678, 2),
Round(1234.5678, -2),
Round(5678.1234, 3),
Round(1234, -3),
Round(5678.1234, -3),
]``````
``````[
1234.57, 1200,
1234.57, 1200,
5678.123, 1000,
6000
]``````
Query metrics:
•    bytesIn: 219

•   bytesOut:  63

• computeOps:   1

•   writeOps:   0

• writeBytes:   0

•  queryTime: 7ms

•    retries:   0

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com