Share via


Funzione round

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

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

Sintassi

round(expr [, targetScale] )

Argomenti

  • expr: espressione numerica.

  • targetScale: espressione INTEGER costante. 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 è il risultato è DECIMALDECIMAL con una scala minore di expr scala e targetScale. Per tutti gli altri tipi numerici, il tipo di risultato corrisponde a expr.

In arrotondamento HALF_UP , la cifra 5 viene arrotondata per errotondare.

Per HALF_EVEN l'arrotondamento, usare la funzione bround.

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