Reference > Functions > Mathematical
Round
- 2005
- 2008
- 2012
- 2014
- 2016
- 2017
- 2019
- 2022
- 2005, 2008, 2012, 2014, 2016, 2017, 2019, 2022
Round Mathematical Function
Use the Round
function to return a numeric value rounded to the specified length or precision.
Syntax
db.fx.Round({expression}, {length} [,{function}])
Arguments
- expression
- – The value to round.
- length
- – Precision to round `expression`.
- function
- – The type of operation to perform.
Returns
Syntax
db.fx.Round({expression}, {length} [,{function}])
Arguments
{expression}
- Any dbExpression element of a numeric data type.{length}
- Precision to round {expression}, must be one of:short
int
long
AnyElement<short>
AnyElement<int>
AnyElement<long>
{function}
- The type of operation to perform, must be one of:short
int
long
AnyElement<short>
AnyElement<int>
AnyElement<long>
Returns
expression type | return type |
---|---|
byte | byte |
byte? | byte? |
AnyElement<byte> | byte |
AnyElement<byte?> | byte? |
decimal | decimal |
decimal? | decimal? |
AnyElement<decimal> | decimal |
AnyElement<decimal?> | decimal? |
double | double |
double? | double? |
AnyElement<double> | double |
AnyElement<double?> | double? |
float | float |
float? | float? |
AnyElement<float> | float |
AnyElement<float?> | float? |
int | int |
int? | int? |
AnyElement<int> | int |
AnyElement<int?> | int? |
long | long |
long? | long? |
AnyElement<long> | long |
AnyElement<long?> | long? |
short | short |
short? | short? |
AnyElement<short> | short |
AnyElement<short?> | short? |
Examples
Select Statement
Round of total purchase amount for all purchases to the nearest dollar.
IEnumerable<double> value = db.SelectMany(
db.fx.Round(dbo.Purchase.TotalPurchaseAmount, 0)
)
.From(dbo.Purchase)
.Execute();
Where Clause
Select all purchase ids where the rounded value is equal to 100.
IEnumerable<int> value = db.SelectMany(
dbo.Purchase.Id
)
.From(dbo.Purchase)
.Where(db.fx.Round(dbo.Purchase.TotalPurchaseAmount, -1) == 100)
.Execute();
Order By Clause
Select the floor value of total purchase amount for all purchases ordered by the floor value descending.
IEnumerable<double> value = db.SelectMany(
dbo.Purchase.TotalPurchaseAmount
)
.From(dbo.Purchase)
.OrderBy(db.fx.Round(dbo.Purchase.TotalPurchaseAmount, 1).Desc())
.Execute();
Group By Clause
Select the payment method and floor of total purchase amount for all purchases, grouped by payment method type and ordered by the floor of total purchase amount.
IEnumerable<dynamic> values = db.SelectMany(
dbo.Purchase.PaymentMethodType,
db.fx.Round(dbo.Purchase.TotalPurchaseAmount, 2).As("TotalPurchaseAmount")
)
.From(dbo.Purchase)
.GroupBy(
dbo.Purchase.PaymentMethodType,
db.fx.Round(dbo.Purchase.TotalPurchaseAmount, 2)
)
.Execute();
Having Clause
Select the payment method and absolute value of total purchase amount for all purchases, grouped by payment method type having an absolute value greater than 10 and ordered by the absolute value of total purchase amount.
IEnumerable<dynamic> values = db.SelectMany(
dbo.Purchase.PaymentMethodType,
dbo.Purchase.TotalPurchaseAmount
)
.From(dbo.Purchase)
.GroupBy(
dbo.Purchase.PaymentMethodType,
dbo.Purchase.TotalPurchaseAmount
)
.Having(db.fx.Round(dbo.Purchase.TotalPurchaseAmount, 2) > 10)
.Execute();