{
  "category": "Text functions",
  "display_name": "RIGHTB",
  "entry_kind": "built_in_function",
  "eval_api": {
    "method": "POST",
    "url": "https://handbook.dnacalc.com/api/eval"
  },
  "function_id": "FUNC.RIGHTB",
  "implementation_state": {
    "answer_bank": null,
    "detail": "Recorded: 5 workbook cells.",
    "dnacalc_commit": "9e1884369a678158dd82d3d74188daf986995e87",
    "in_catalogue": true,
    "state": "matches",
    "state_label": "Matches every recorded Excel answer",
    "summary": "Matches all 5 recorded answers",
    "workbook_corpus": {
      "cells": 5,
      "matched": 5
    }
  },
  "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#L278-L278"
      ],
      "repository": "https://github.com/DnaCalc/DnaCalc",
      "shared_code": [
        "catalogue/text_functions::single_byte",
        "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#L278-L278",
      "state": "matches",
      "suite": null,
      "summary": "Matches all 5 recorded answers"
    }
  ],
  "json_url": "https://handbook.dnacalc.com/api/functions/FUNC.RIGHTB.json",
  "name": "RIGHTB",
  "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- **[RIGHT](FUNC.RIGHT.md)** — the character-counting twin, documented by Microsoft on the same\n  page. The Handbook publishes them as two entries because they count in two different units.\n- **`LEFTB`** — the head-anchored byte slice, and the one place where the partial-character\n  question can be studied from the other end of the string.\n- **`LENB`, `FINDB`, `SEARCHB`, [MIDB](FUNC.MIDB.md), [REPLACEB](FUNC.REPLACEB.md)** — the rest\n  of the B family, sharing one implementing module and this page's central caveat.\n- **`LENB`** is the only function that produces coordinates in the same byte space, so it is\n  the companion for reasoning about `RIGHTB` at all.\n\n\n",
    "how-to-implement": "\n### Notes for implementers\n\n\nBackwards byte counting over a variable-width encoding is not a symmetric operation. Finding\nthe byte `n - k + 1` requires knowing the byte length of every character in the string, so\n`RIGHTB` cannot be implemented as a reverse scan of characters — it needs the full byte\naccounting that `LENB` computes.\n\nThe default of 1 makes the partial-character case the *cheapest* call to write, not the rarest,\nwhich is an argument for deciding it deliberately rather than letting it fall out of an\nimplementation detail.\n\nA test vector for `RIGHTB` that does not record the default editing language records nothing.\nThe same inputs have two legitimately different correct answers.\n\n\n",
    "quirks": "\n### Result and edge cases\n\n\nReturns `Text`.\n\nThe rules Microsoft documents for `RIGHT` are stated on the same page for `RIGHTB` with\n\"characters\" replaced by \"bytes\": the count must be non-negative, a count greater than the\nlength of `text` returns all of `text`, and an omitted count means 1.\n\nThe distinctively `RIGHTB` question is undocumented: **what happens when the byte window\nbegins inside a double-byte character.** Because the window is anchored at the end and\nmeasured backwards in bytes, an odd `num_bytes` over double-byte text lands mid-character by\nconstruction. Excel could drop the partial character, return its orphaned byte, round the\nboundary outward to include the whole character, or error. Microsoft's page names none of\nthese, and the Handbook does not know which it is.\n\n\n### Errors\n\n\n| Error | Condition | Source |\n|---|---|---|\n| `#VALUE!` | `num_bytes` is negative. | Implied by the documented non-negativity requirement; the page states the requirement, not the error code. |\n| `#VALUE!` | Non-numeric text in `num_bytes`, or a value that cannot convert to text in `text`. | Shared coercion rules, not `RIGHTB`-specific. |\n\nWhether a partial-character window is an error condition at all is the open question above.\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, the default of 1, and the\n  DBCS default-language condition for the B family).\n- Handbook, [The value universe](../model/01-value-universe.md) — worksheet text as UTF-16\n  code units, which the byte view must be reconciled against.\n- Handbook, [Coercion and lifting](../model/02-coercion-and-lifting.md) — numeric-argument\n  coercion and error propagation.\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`RIGHTB(text, [num_bytes])` returns the last `num_bytes` **bytes** of `text`.\n\nIt is [RIGHT](FUNC.RIGHT.md) with one unit changed, and the change only takes effect under one\ncondition. Microsoft's rule for the whole B family:\n\n> The B functions count each double-byte character as 2 **only when a DBCS language has been\n> enabled for editing and set as the default language**. Otherwise they count each character\n> as 1.\n\nSo on most installations `RIGHTB` is `RIGHT`. On a machine whose default editing language is\nJapanese, Chinese (Simplified or Traditional) or Korean, the same call takes a different — and\ngenerally shorter — slice of the same string. The active default language is an unlisted input\nto this function, and any recorded result for it that omits that setting is incomplete.\n\nThe bytes are those of the **DBCS code page for the active language** — Shift-JIS, GBK, Big5,\nEUC-KR — not UTF-8 and not UTF-16.\n\n\n\n### Arguments\n\n\n| Argument | Meaning | Default |\n|---|---|---|\n| `text` | The string to slice. Required. | — |\n| `num_bytes` | How many bytes to take from the end. Optional; must be zero or greater. | 1 |\n\nThe signature is `RIGHT`'s with `num_chars` renamed. The count is optional here just as it is\non `RIGHT`, and defaults to 1 — which under DBCS means \"one byte\", i.e. potentially half a\ncharacter. That is not a hypothetical: `RIGHTB(A1)` on a string ending in a double-byte\ncharacter is the partial-character case, reached by the shortest possible call.\n\n\n"
  },
  "signature": {
    "display": "RIGHTB(text, [num_bytes])",
    "parameters": [
      {
        "description": null,
        "name": "text",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "num_bytes",
        "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, counted in bytes for double-byte languages",
        "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": "RIGHTB"
        },
        {
          "locale": "bg-BG",
          "name": "RIGHTB"
        },
        {
          "locale": "cs-CZ",
          "name": "RIGHTB"
        },
        {
          "locale": "da-DK",
          "name": "HØJREB"
        },
        {
          "locale": "de-DE",
          "name": "RIGHTB"
        },
        {
          "locale": "el-GR",
          "name": "RIGHTB"
        },
        {
          "locale": "en-AU",
          "name": "RIGHTB"
        },
        {
          "locale": "en-GB",
          "name": "RIGHTB"
        },
        {
          "locale": "en-US",
          "name": "RIGHTB"
        },
        {
          "locale": "es-ES",
          "name": "DERECHAB"
        },
        {
          "locale": "et-EE",
          "name": "RIGHTB"
        },
        {
          "locale": "fi-FI",
          "name": "OIKEAB"
        },
        {
          "locale": "fr-FR",
          "name": "DROITEB"
        },
        {
          "locale": "he-IL",
          "name": "RIGHTB"
        },
        {
          "locale": "hr-HR",
          "name": "RIGHTB"
        },
        {
          "locale": "hu-HU",
          "name": "JOBB2"
        },
        {
          "locale": "id-ID",
          "name": "RIGHTB"
        },
        {
          "locale": "it-IT",
          "name": "RIGHTB"
        },
        {
          "locale": "ja-JP",
          "name": "RIGHTB"
        },
        {
          "locale": "ko-KR",
          "name": "RIGHTB"
        },
        {
          "locale": "lt-LT",
          "name": "RIGHTB"
        },
        {
          "locale": "lv-LV",
          "name": "RIGHTB"
        },
        {
          "locale": "nb-NO",
          "name": "RIGHTB"
        },
        {
          "locale": "nl-NL",
          "name": "RECHTSB"
        },
        {
          "locale": "pl-PL",
          "name": "PRAWY.B"
        },
        {
          "locale": "pt-BR",
          "name": "RIGHTB"
        },
        {
          "locale": "pt-PT",
          "name": "DIREITAB"
        },
        {
          "locale": "ro-RO",
          "name": "RIGHTB"
        },
        {
          "locale": "ru-RU",
          "name": "ПРАВБ"
        },
        {
          "locale": "sk-SK",
          "name": "RIGHTB"
        },
        {
          "locale": "sl-SI",
          "name": "RIGHTB"
        },
        {
          "locale": "sr-Latn-RS",
          "name": "RIGHTB"
        },
        {
          "locale": "sv-SE",
          "name": "HÖGERB"
        },
        {
          "locale": "th-TH",
          "name": "RIGHTB"
        },
        {
          "locale": "tr-TR",
          "name": "SAĞB işlevleri"
        },
        {
          "locale": "uk-UA",
          "name": "RIGHTB"
        },
        {
          "locale": "vi-VN",
          "name": "RIGHTB"
        },
        {
          "locale": "zh-CN",
          "name": "RIGHTB"
        },
        {
          "locale": "zh-HK",
          "name": "RIGHTB"
        },
        {
          "locale": "zh-TW",
          "name": "RIGHTB"
        }
      ],
      "signature": {
        "display": "RIGHTB(text, [num_bytes])",
        "parameters": [
          {
            "description": null,
            "name": "text",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "num_bytes",
            "optional": true,
            "repeats": false
          }
        ],
        "trailing_repeats": false
      },
      "surface_name": "RIGHTB",
      "version_marker": null,
      "xlcall": null
    },
    "microsoft": "https://support.microsoft.com/en-us/office/right-function-240267ee-9afa-4639-a02b-f19e1786cf2f"
  },
  "try_it": {
    "formula": "=RIGHTB(\"handbook\",4)"
  },
  "url": "https://handbook.dnacalc.com/functions/RIGHTB.html",
  "variants": [],
  "versions": []
}