{
  "category": "Text functions",
  "display_name": "RIGHT",
  "entry_kind": "built_in_function",
  "eval_api": {
    "method": "POST",
    "url": "https://handbook.dnacalc.com/api/eval"
  },
  "function_id": "FUNC.RIGHT",
  "implementation_state": {
    "answer_bank": null,
    "detail": "Recorded: 14 workbook cells.",
    "dnacalc_commit": "9e1884369a678158dd82d3d74188daf986995e87",
    "in_catalogue": true,
    "state": "matches",
    "state_label": "Matches every recorded Excel answer",
    "summary": "Matches all 14 recorded answers",
    "workbook_corpus": {
      "cells": 14,
      "matched": 14
    }
  },
  "implementations": [
    {
      "commit": "9e1884369a678158dd82d3d74188daf986995e87",
      "flavour": "excel-compatibility-candidate",
      "language": "Rust",
      "name": "CalcFunc",
      "own_code": [
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/text_functions.rs#L270-L270"
      ],
      "repository": "https://github.com/DnaCalc/DnaCalc",
      "shared_code": [
        "catalogue/text_functions::side_count",
        "catalogue/text_functions::right",
        "ported/text_kernels::text",
        "ported/text_kernels::text_from_str",
        "ported/text_kernels::date_integer_floor",
        "ported/text_kernels::nonnegative_count",
        "ported/text_kernels::unit_width",
        "ported/text_kernels::character_boundary",
        "ported/text_kernels::slice_character_count",
        "ported/text_kernels::take_right",
        "ported/text_kernels::truncated",
        "ported/text_kernels::push_singleton_or_original",
        "ported/text_kernels::push_upper",
        "ported/text_kernels::upper"
      ],
      "source": "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/text_functions.rs#L270-L270",
      "state": "matches",
      "suite": null,
      "summary": "Matches all 14 recorded answers"
    }
  ],
  "json_url": "https://handbook.dnacalc.com/api/functions/FUNC.RIGHT.json",
  "name": "RIGHT",
  "notes": [],
  "schema": "efh.function-reference/v1",
  "section_order": [
    "what-it-does",
    "try-it",
    "quirks",
    "how-to-implement",
    "version-differences",
    "alternatives"
  ],
  "sections": {
    "alternatives": "\n### Relationships\n\n\n- **`LEFT`** is the mirror image, with the same optional-count-defaults-to-1 signature.\n- **[MID](FUNC.MID.md)** is the unanchored slice; `RIGHT(t, k)` equals `MID(t, LEN(t)-k+1, k)`\n  within the valid range, and the equivalence breaks at `k > LEN(t)`, where `RIGHT` clamps and\n  the `MID` expression computes a `start_num` below 1 and errors.\n- **[RIGHTB](FUNC.RIGHTB.md)** is the byte-counting sibling, documented by Microsoft on the\n  same page and published by the Handbook as its own entry.\n- **`TEXTAFTER`** is the modern alternative when the tail is delimited rather than counted —\n  `TEXTAFTER(a, \"@\")` instead of `RIGHT(a, LEN(a) - FIND(\"@\", a))`. `RIGHT` is not superseded;\n  fixed-width tails are still its job.\n- Readers confuse `RIGHT` with `TRIM` when stripping trailing spaces. `RIGHT` cannot strip\n  anything — it takes a fixed count from the end regardless of content.\n\n\n",
    "how-to-implement": "\n### Notes for implementers\n\n\nThe clamp is one-sided and asymmetric with `MID`: `RIGHT` clamps an over-long count silently,\nwhile `MID` errors on an under-1 start. An implementation that routes `RIGHT` through a shared\n`MID` kernel has to clamp *before* computing the start position, or it will turn a documented\nclamp into an error.\n\nBecause `num_chars` counts code units, `RIGHT` can split a surrogate pair and return a\ndangling low surrogate. The value-universe chapter records that ill-formed UTF-16 is a\nreachable state in this model, so downstream text handling has to survive it rather than\nassume well-formedness.\n\n`RIGHT` on a number is a to-text conversion followed by a slice, and the to-text step is the\npart that is not pinned. Any implementation matching Excel here is really matching Excel's\ngeneral-format number rendering.\n\n\n",
    "quirks": "\n### Result and edge cases\n\n\nReturns `Text`.\n\nThe boundary rules Microsoft documents on the `RIGHT` page:\n\n- `num_chars` must be greater than or equal to zero.\n- `num_chars` greater than the length of `text` returns all of `text` — no error, no padding.\n- `num_chars` omitted is treated as 1.\n\nNumbers arriving in `text` are converted to text first, which is the standard trap for anyone\nslicing formatted values: `RIGHT` sees the general-format rendering of the number, not what the\ncell displays. The cell's number format is presentation and does not reach the function. The\nto-text rules are shared and only outlined in\n[Coercion and lifting](../model/02-coercion-and-lifting.md); this is a real gap, not a\nsimplification.\n\n\n### Errors\n\n\n| Error | Condition | Source |\n|---|---|---|\n| `#VALUE!` | `num_chars` is negative. | Implied by the documented \"must be greater than or equal to zero\"; the page states the requirement rather than the error value. |\n| `#VALUE!` | Non-numeric text in `num_chars`, or a value that cannot convert to text in `text`. | Shared coercion rules, not `RIGHT`-specific. |\n\nNote the honest weakness in the first row: Microsoft's page states a requirement on the\nargument, not the error code produced when it is violated. `#VALUE!` is what the sibling\npages document for the analogous violation, and it is what the Handbook expects — but it is an\ninference here, and it is on the probe list below.\n\n\n",
    "sources": "- Microsoft, \"RIGHT, RIGHTB functions\" —\n  <https://support.microsoft.com/en-us/office/right-function-240267ee-9afa-4639-a02b-f19e1786cf2f>\n  (signature, the non-negative requirement, the over-long clamp, and the default of 1).\n- Handbook, [The value universe](../model/01-value-universe.md) — text as UTF-16 code units,\n  the text cap, and reachable ill-formed UTF-16.\n- Handbook, [Coercion and lifting](../model/02-coercion-and-lifting.md) — to-number coercion of\n  `num_chars`, the outline-level status of to-text, and the Empty/Missing distinction.\n\n\n",
    "version-differences": "No comparison between specific Excel builds is recorded here yet. This does not establish that all builds behave alike.",
    "what-it-does": "\n`RIGHT(text, [num_chars])` returns the last `num_chars` characters of `text`.\n\nWith `n = LEN(text)`:\n\n```\nRIGHT(t, k)  =  characters at positions n - k + 1 … n      for 0 <= k <= n\nRIGHT(t, k)  =  t                                          for k > n\nRIGHT(t, 0)  =  \"\"\n```\n\nThe anchoring is what distinguishes it from [MID](FUNC.MID.md): `RIGHT` counts from the end,\nso the window moves when `text` changes length. `MID(t, LEN(t) - k + 1, k)` is the same slice\nwritten from the other end, and the arithmetic in that expression is precisely the arithmetic\n`RIGHT` exists to avoid.\n\n\"Character\" means one UTF-16 code unit — the unit `LEN` counts and the unit the Handbook's\nvalue universe defines worksheet text in. See\n[The value universe](../model/01-value-universe.md), \"Text, exactly\".\n\n\n\n### Arguments\n\n\n| Argument | Meaning | Default |\n|---|---|---|\n| `text` | The string to slice. Required. | — |\n| `num_chars` | How many characters to take from the end. Optional; must be zero or greater. | 1 |\n\nThe optional second argument is the family's least uniform feature and worth flagging: `RIGHT`\nand `LEFT` default their count to 1, while `MID` requires all three of its arguments. A bare\n`RIGHT(A1)` is a legal one-character slice; a bare `MID(A1, 2)` is not a legal call at all.\n\n`num_chars` is a numeric slot subject to ordinary to-number coercion; see\n[Coercion and lifting](../model/02-coercion-and-lifting.md).\n\n\n"
  },
  "signature": {
    "display": "RIGHT(text, [num_chars])",
    "parameters": [
      {
        "description": null,
        "name": "text",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "num_chars",
        "optional": true,
        "repeats": false
      }
    ],
    "trailing_repeats": false
  },
  "sources": {
    "metadata": {
      "admission": {
        "label": "implemented",
        "reason": null
      },
      "arity": {
        "max": 2,
        "min": 1
      },
      "category": "Text functions",
      "classification": {
        "arg_preparation_profile": "ValuesOnlyPreAdapter",
        "coercion_lift_profile": "None",
        "determinism_class": "Deterministic",
        "error_collapse_profile": "None",
        "fec_dependency_profile": "None",
        "host_interaction_class": "None",
        "kernel_signature_class": "Custom",
        "rich_value_usage": "RichBlind",
        "surface_fec_dependency_profile": "RefOnly",
        "thread_safety_class": "SafePure",
        "volatility_class": "NonVolatile"
      },
      "descriptions": {
        "long": null,
        "short": "The last characters of a text",
        "short_source": "dna-calc-own"
      },
      "docs": {
        "english_description": "Returns the rightmost characters from a text value",
        "microsoft_url": "https://support.microsoft.com/en-us/office/right-function-240267ee-9afa-4639-a02b-f19e1786cf2f"
      },
      "entry_kind": "built_in_function",
      "localized_family_names": null,
      "localized_names": [
        {
          "locale": "ar-SA",
          "name": "RIGHT"
        },
        {
          "locale": "bg-BG",
          "name": "RIGHT"
        },
        {
          "locale": "cs-CZ",
          "name": "ZPRAVA"
        },
        {
          "locale": "da-DK",
          "name": "HØJRE"
        },
        {
          "locale": "de-DE",
          "name": "RIGHT"
        },
        {
          "locale": "el-GR",
          "name": "RIGHT"
        },
        {
          "locale": "en-AU",
          "name": "RIGHT"
        },
        {
          "locale": "en-GB",
          "name": "RIGHT"
        },
        {
          "locale": "en-US",
          "name": "RIGHT"
        },
        {
          "locale": "es-ES",
          "name": "DERECHA"
        },
        {
          "locale": "et-EE",
          "name": "RIGHT"
        },
        {
          "locale": "fi-FI",
          "name": "OIKEA"
        },
        {
          "locale": "fr-FR",
          "name": "DROITE"
        },
        {
          "locale": "he-IL",
          "name": "RIGHT"
        },
        {
          "locale": "hr-HR",
          "name": "RIGHT"
        },
        {
          "locale": "hu-HU",
          "name": "JOBB"
        },
        {
          "locale": "id-ID",
          "name": "RIGHT"
        },
        {
          "locale": "it-IT",
          "name": "RIGHT"
        },
        {
          "locale": "ja-JP",
          "name": "RIGHT"
        },
        {
          "locale": "ko-KR",
          "name": "RIGHT"
        },
        {
          "locale": "lt-LT",
          "name": "RIGHT"
        },
        {
          "locale": "lv-LV",
          "name": "RIGHT"
        },
        {
          "locale": "nb-NO",
          "name": "RIGHT"
        },
        {
          "locale": "nl-NL",
          "name": "RECHTS"
        },
        {
          "locale": "pl-PL",
          "name": "PRAWY"
        },
        {
          "locale": "pt-BR",
          "name": "RIGHT"
        },
        {
          "locale": "pt-PT",
          "name": "DIREITA"
        },
        {
          "locale": "ro-RO",
          "name": "RIGHT"
        },
        {
          "locale": "ru-RU",
          "name": "ПРАВСИМВ"
        },
        {
          "locale": "sk-SK",
          "name": "RIGHT"
        },
        {
          "locale": "sl-SI",
          "name": "RIGHT"
        },
        {
          "locale": "sr-Latn-RS",
          "name": "RIGHT"
        },
        {
          "locale": "sv-SE",
          "name": "HÖGER"
        },
        {
          "locale": "th-TH",
          "name": "RIGHT"
        },
        {
          "locale": "tr-TR",
          "name": "SAĞDAN"
        },
        {
          "locale": "uk-UA",
          "name": "RIGHT"
        },
        {
          "locale": "vi-VN",
          "name": "RIGHT"
        },
        {
          "locale": "zh-CN",
          "name": "RIGHT"
        },
        {
          "locale": "zh-HK",
          "name": "RIGHT"
        },
        {
          "locale": "zh-TW",
          "name": "RIGHT"
        }
      ],
      "signature": {
        "display": "RIGHT(text, [num_chars])",
        "parameters": [
          {
            "description": null,
            "name": "text",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "num_chars",
            "optional": true,
            "repeats": false
          }
        ],
        "trailing_repeats": false
      },
      "surface_name": "RIGHT",
      "version_marker": null,
      "xlcall": null
    },
    "microsoft": "https://support.microsoft.com/en-us/office/right-function-240267ee-9afa-4639-a02b-f19e1786cf2f"
  },
  "try_it": {
    "formula": "=RIGHT(\"handbook\",4)"
  },
  "url": "https://handbook.dnacalc.com/functions/RIGHT.html",
  "variants": [],
  "versions": []
}