Signed fixed-point numbers that keep precision during add, subtract and multiply operations. For division least significant digits are discarded (not rounded).
## Parameters {#parameters}
- P - precision. Valid range: \[ 1 : 38\]. Determines how many decimal digits number can have (including fraction).
- P - precision. Valid range: \[ 1 : 76\]. Determines how many decimal digits number can have (including fraction).
- S - scale. Valid range: \[ 0 : P \]. Determines how many decimal digits fraction can have.
Depending on P parameter value Decimal(P, S) is a synonym for:
@@ -11,7 +11,7 @@ When you convert a value from one to another data type, you should remember that
ClickHouse has the [same behavior as C++ programs](https://en.cppreference.com/w/cpp/language/implicit_conversion).
## toInt(8\|16\|32\|64) {#toint8163264}
## toInt(8\|16\|32\|64\|128\|256) {#toint8163264}
Converts an input value to the [Int](../../sql-reference/data-types/int-uint.md) data type. This function family includes:
...
...
@@ -19,6 +19,8 @@ Converts an input value to the [Int](../../sql-reference/data-types/int-uint.md)
-`toInt16(expr)` — Results in the `Int16` data type.
-`toInt32(expr)` — Results in the `Int32` data type.
-`toInt64(expr)` — Results in the `Int64` data type.
-`toInt128(expr)` — Results in the `Int128` data type.
-`toInt256(expr)` — Results in the `Int256` data type.
**Parameters**
...
...
@@ -26,7 +28,7 @@ Converts an input value to the [Int](../../sql-reference/data-types/int-uint.md)
**Returned value**
Integer value in the `Int8`, `Int16`, `Int32`, or `Int64` data type.
Integer value in the `Int8`, `Int16`, `Int32`, `Int64`, `Int128` or `Int256` data type.
Functions use [rounding towards zero](https://en.wikipedia.org/wiki/Rounding#Rounding_towards_zero), meaning they truncate fractional digits of numbers.
Converts an input value to the [UInt](../../sql-reference/data-types/int-uint.md) data type. This function family includes:
...
...
@@ -84,6 +86,7 @@ Converts an input value to the [UInt](../../sql-reference/data-types/int-uint.md
-`toUInt16(expr)` — Results in the `UInt16` data type.
-`toUInt32(expr)` — Results in the `UInt32` data type.
-`toUInt64(expr)` — Results in the `UInt64` data type.
-`toUInt256(expr)` — Results in the `UInt256` data type.
**Parameters**
...
...
@@ -91,7 +94,7 @@ Converts an input value to the [UInt](../../sql-reference/data-types/int-uint.md
**Returned value**
Integer value in the `UInt8`, `UInt16`, `UInt32`, or `UInt64` data type.
Integer value in the `UInt8`, `UInt16`, `UInt32`, `UInt64` or `UInt256` data type.
Functions use [rounding towards zero](https://en.wikipedia.org/wiki/Rounding#Rounding_towards_zero), meaning they truncate fractional digits of numbers.
Converts `value` to the [Decimal](../../sql-reference/data-types/decimal.md) data type with precision of `S`. The `value` can be a number or a string. The `S` (scale) parameter specifies the number of decimal places.
Converts an input string to a [Nullable(Decimal(P,S))](../../sql-reference/data-types/decimal.md) data type value. This family of functions include:
-`toDecimal32OrNull(expr, S)` — Results in `Nullable(Decimal32(S))` data type.
-`toDecimal64OrNull(expr, S)` — Results in `Nullable(Decimal64(S))` data type.
-`toDecimal128OrNull(expr, S)` — Results in `Nullable(Decimal128(S))` data type.
-`toDecimal256OrNull(expr, S)` — Results in `Nullable(Decimal256(S))` data type.
These functions should be used instead of `toDecimal*()` functions, if you prefer to get a `NULL` value instead of an exception in the event of an input value parsing error.
...
...
@@ -183,13 +188,14 @@ SELECT toDecimal32OrNull(toString(-1.111), 2) AS val, toTypeName(val)
Converts an input value to the [Decimal(P,S)](../../sql-reference/data-types/decimal.md) data type. This family of functions include:
-`toDecimal32OrZero( expr, S)` — Results in `Decimal32(S)` data type.
-`toDecimal64OrZero( expr, S)` — Results in `Decimal64(S)` data type.
-`toDecimal128OrZero( expr, S)` — Results in `Decimal128(S)` data type.
-`toDecimal256OrZero( expr, S)` — Results in `Decimal256(S)` data type.
These functions should be used instead of `toDecimal*()` functions, if you prefer to get a `0` value instead of an exception in the event of an input value parsing error.
Знаковые дробные числа с сохранением точности операций сложения, умножения и вычитания. Для деления осуществляется отбрасывание (не округление) знаков, не попадающих в младший десятичный разряд.
## Параметры {#parametry}
- P - precision. Значение из диапазона \[ 1 : 38\]. Определяет, сколько десятичных знаков (с учетом дробной части) может содержать число.
- P - precision. Значение из диапазона \[ 1 : 76\]. Определяет, сколько десятичных знаков (с учетом дробной части) может содержать число.
- S - scale. Значение из диапазона \[ 0 : P \]. Определяет, сколько десятичных знаков содержится в дробной части числа.
В зависимости от параметра P Decimal(P, S) является синонимом:
Преобразует `value` к типу данных [Decimal](../../sql-reference/functions/type-conversion-functions.md) с точностью `S`. `value` может быть числом или строкой. Параметр `S` (scale) задаёт число десятичных знаков.
Преобразует входную строку в значение с типом данных [Nullable (Decimal (P, S))](../../sql-reference/functions/type-conversion-functions.md). Семейство функций включает в себя:
-`toDecimal32OrNull(expr, S)` — Возвращает значение типа `Nullable(Decimal32(S))`.
-`toDecimal64OrNull(expr, S)` — Возвращает значение типа `Nullable(Decimal64(S))`.
-`toDecimal128OrNull(expr, S)` — Возвращает значение типа `Nullable(Decimal128(S))`.
-`toDecimal256OrNull(expr, S)` — Возвращает значение типа `Nullable(Decimal256(S))`.
Эти функции следует использовать вместо функций `toDecimal*()`, если при ошибке обработки входного значения вы хотите получать `NULL` вместо исключения.
...
...
@@ -178,13 +183,14 @@ SELECT toDecimal32OrNull(toString(-1.111), 2) AS val, toTypeName(val)