Share via


Funzione bround

Si applica a:segno di spunta sì Databricks SQL segno di spunta sì Databricks Runtime

Restituisce l'oggetto arrotondato utilizzando HALF_EVEN la modalità di arrotondamentoexpr.

Sintassi

bround(expr [,targetScale] )

Argomenti

  • expr: espressione numerica.

  • targetScale: espressione costante INTEGER. Se targetScale viene omesso, il valore predefinito è 0 (numero intero).

    In Databricks SQL e Databricks Runtime 12.2 LTS e versioni successive: se targetscale l'arrotondamento è negativo viene eseguito a potenze positive di 10.

Valori restituiti

Se expr è DECIMAL, il risultato è DECIMAL con una scala minore di expr scala e max(targetScale, 0). Per tutti gli altri tipi numerici, il tipo di risultato corrisponde a expr.

In HALF_EVEN arrotondamento, noto anche come arrotondamento gaussiano o banchiere , la cifra viene arrotondata verso una cifra 5 pari.

Per HALF_UP l'arrotondamento, usare la funzione rotonda.

Avviso

In Databricks Runtime 12.2 LTS e versioni successive e in Databricks Runtime se spark.sql.ansi.enabled è false, un overflow non genera un errore ma "esegue il wrapping" del risultato.

Esempi

> SELECT bround(2.5, 0), round(2.5, 0);
 2    3

> SELECT bround(3.5, 0), round(3.5, 0);
 4    4

> SELECT bround(2.6, 0), round(2.6, 0);
 3    3

> SELECT bround(2.25, 1), round(2.25, 1);;
 2.2  2.3

> SELECT bround(13.5, -1), round(13.5, -1);
 10   10