Logo

MROUND

Updated 2023-10-13 20:30:12.617000

Syntax

SELECT [westclintech].[wct].[MROUND] (
  <@Number, float,>
 ,<@Multiple, float,>)

Description

Use the scalar function MROUND to calculate a number rounded to the desired multiple.

Arguments

@Multiple

is the multiple to which the number is to be rounded. @Multiple is an expression of type float or of a type that can be implicitly converted to float.

@Number

is the number to rounded up. @Number is an expression of type float or of a type that can be implicitly converted to float.

Return Type

float

Remarks

MROUND rounds up, away from zero, if the remainder of dividing number by multiple is greater than or equal to half the value of multiple.

Examples

select wct.MROUND(21,5);

Here is the result set.

{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"20"}]}

The following example illustrates how to use the MROUND function with dates and times, by rounding a date and time to the nearest 15 minutes:

select cast(wct.mround(
                          cast(cast('2008-10-23 13:02:24.030' as datetime) as float),
                          cast(cast('00:15:00' as datetime) as float)
                      ) as datetime);

Here is the result set.

{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"2008-10-23 13:00:00.000"}]}