Documentation/Calc Functions/DECIMAL

    From The Document Foundation Wiki
    Other languages:


    Function name:

    DECIMAL

    Category:

    Text

    Summary:

    Converts the text representation of a number in a specified base / radix to a decimal number.

    The DECIMAL function is complementary to the BASE function.

    Syntax:

    DECIMAL(Text; Radix)

    Returns:

    Returns a non-negative integer that is the decimal number obtained by converting the specified text string using the given base / radix.

    Arguments:

    Text is a string (in quotation marks), or a reference to a cell containing that string, that contains the characters of the number that is to be converted to decimal. For any valid value of the Radix argument, if the value to be converted only contains digits (0 to 9) then it may also be passed as a number or a reference to a cell containing that number. In such a case, the content of Text may appear to be decimal but DECIMAL will interpret it correctly in its intended base.

    Radix is an integer in the range 2 ≤ r ≤ 36, or a reference to a cell containing such an integer, that is the base / radix to be used for the conversion.

    • If Text contains a character that is not valid for the specified Radix, then DECIMAL reports an invalid argument error (Err:502). The following rules govern the validity of the characters in Text.
    1. Leading space and tab characters are valid and ignored.
    2. Leading zeroes are valid and ignored.
    3. Where letters can appear within Text, both uppercase and lowercase letters are accepted and treated as equals.
    4. The following table lists the characters allowed in Text for each base. For brevity, only the uppercase letters are listed in the table.
    Characters accepted for bases/radixes
    Base/Radix Expected characters
    2 (binary) Digits 0 and 1.
    It is common to add a suffix "B" or "b" to a binary number, for example "100111B". DECIMAL accepts such a suffix.
    3 Digits 0 to 2
    4 Digits 0 to 3
    5 Digits 0 to 4
    6 Digits 0 to 5
    7 Digits 0 to 6
    8 (octal) Digits 0 to 7
    9 Digits 0 to 8
    10 (decimal) Digits 0 to 9
    11 Digits 0 to 9 and character A (10)
    12 Digits 0 to 9 and characters A (10) and B (11)
    13 Digits 0 to 9 and characters A (10) to C (12)
    14 Digits 0 to 9 and characters A (10) to D (13)
    15 Digits 0 to 9 and characters A (10) to E (14)
    16 (hexadecimal) Digits 0 to 9 and characters A (10) to F (15).
    It is common to add a prefix "0X", "0x", "X", or "x" to a hexadecimal number, for example "0X1AF". DECIMAL accepts such a prefix.

    It is also common to add a suffix "H" or "h" to a hexadecimal number, for example "1AFH". DECIMAL accepts such a suffix.

    17 Digits 0 to 9 and characters A (10) to G (16)
    18 Digits 0 to 9 and characters A (10) to H (17)
    19 Digits 0 to 9 and characters A (10) to I (18)
    20 Digits 0 to 9 and characters A (10) to J (19)
    21 Digits 0 to 9 and characters A (10) to K (20)
    22 Digits 0 to 9 and characters A (10) to L (21)
    23 Digits 0 to 9 and characters A (10) to M (22)
    24 Digits 0 to 9 and characters A (10) to N (23)
    25 Digits 0 to 9 and characters A (10) to O (24)
    26 Digits 0 to 9 and characters A (10) to P (25)
    27 Digits 0 to 9 and characters A (10) to Q (26)
    28 Digits 0 to 9 and characters A (10) to R (27)
    29 Digits 0 to 9 and characters A (10) to S (28)
    30 Digits 0 to 9 and characters A (10) to T (29)
    31 Digits 0 to 9 and characters A (10) to U (30)
    32 Digits 0 to 9 and characters A (10) to V (31)
    33 Digits 0 to 9 and characters A (10) to W (32)
    34 Digits 0 to 9 and characters A (10) to X (33)
    35 Digits 0 to 9 and characters A (10) to Y (34)
    36 Digits 0 to 9 and characters A (10) to Z (35)
    • If Text is set to the empty string, DECIMAL returns 0 for any valid value of Radix.
    • If Radix is non-numeric, then DECIMAL reports a #VALUE! error.
    • For any non-integer value of Radix, DECIMAL truncates the value to an integer.
    • If, after any truncation, Radix is less than 2 or greater than 36, then DECIMAL reports an invalid argument error (Err:502).

    Additional details:

    The positional numeral systems for each base have been given names that are listed on Wikipedia's List of numeral systems page.

    For a non-negative integer x and a valid base b, note that x = DECIMAL(BASE(x; b); b).

    Examples:

    Formula Description Returns
    =DECIMAL(1111; 2) Here the function returns the number 15, which is the decimal value that corresponds to 1111 in binary notation. The same value would be returned if the first argument were to be replaced with "1111b" – note that the value must be passed as a string if it contains any non-numeric characters. 15
    =DECIMAL(" 0017"; 8.3) Here the function returns the number 15, which is the decimal value that corresponds to "17" in octal notation. DECIMAL ignores the leading spaces and zeroes in the text of the first argument and truncates the second argument to base 8. 15
    =DECIMAL(D1; D2) where cells D1 and D2 contain the numbers 56 and 10 respectively. Here the function returns the number 56. 56
    =DECIMAL("AF"; 16) Here the function returns the number 175, which is the decimal value that corresponds to "AF" in hexadecimal notation. The same value would be returned if the first argument were to be replaced with any of "af", "xAF", "0XAF", or "AFh". 175
    =DECIMAL("AV"; 32) Here the function returns the number 351, which is the decimal value that corresponds to "AV" in duotrigesimal (base 32) notation. 351
    =DECIMAL("az"; 36) Here the function returns the number 395, which is the decimal value that corresponds to "az" in hexatrigesimal (base 36) notation. 395
    =DECIMAL("FACE"; 16) Here the function returns the number 64206, which is the decimal value that corresponds to "FACE" in hexadecimal notation. 64206

    Related LibreOffice functions:

    BASE

    ODF standard:

    Section 6.19.10, part 2

    Related (or similar) Excel functions:

    DECIMAL since v.2013.