RIGHTB Function (LibreOffice Calc)
Learn the RIGHTB function in LibreOffice Calc: Returns the last character or characters of a text, with DBCS.
Verification status: Official documentation referenced; example outcomes independently reasoned or arithmetically checked where stated. Not executed in LibreOffice Calc. How formula examples are checked
Validation scope: References to observed, native-tested, or executed results below describe the saved LibreOffice Calc 25.2.3.2 Linux test evidence dated 12 October 2026. On 13 October, its script and artifact hashes, all 86 ODS/JSON case pairs, and the current official function documentation were checked; CJK/ASCII worked examples were independently reasoned through. Calc was not rerun for this review. Historical observations do not certify other versions, platforms, locales, or workbook imports.
RIGHTB extracts a suffix counted in DBCS-style byte units, not ordinary character positions. When the requested width cuts through a two-byte character, LibreOffice Calc substitutes a space at the incomplete boundary. Use it for documented legacy byte-width rules, not as a substitute for encoding-aware UTF-8 substring operations.
What RIGHTB does
RIGHTB works from the right end of a string using byte-width accounting that supports double-byte character set (DBCS) text. The closely related RIGHT extracts ordinary characters instead. For 中国, RIGHT("中国";1) selects the character 国; RIGHTB("中国";1) returned one ordinary space in native Calc because one byte cannot hold that entire CJK character. [LO-RIGHTB] [NATIVE]
This space is part of the returned string, not a null value. An exact-match test, a downstream TRIM, or an export validation may therefore respond differently than expected. [LO-RIGHTB]
Syntax and parameters
=RIGHTB(Text [; Number_bytes])
| Argument | Required? | Meaning | Default or limit |
|---|---|---|---|
Text |
Yes | Text value, a cell reference or expression converted to text. | Cannot be omitted. |
Number_bytes |
Optional | Number of DBCS byte units to take from the right. | Defaults to 1. Negative counts generated an error in Calc 25.2. |
Official Help documents RIGHTB beginning in LibreOffice 4.2. Note the argument order: Text first, optional Number_bytes second. For formulas with multiple arguments, Calc’s usual separator is a semicolon (;), but the separator is configurable. Function names may be localized; enable English names in Calc’s Formula preferences if necessary. No ODF-specific alternate function name was established for this page. [LO-RIGHTB] [LO-OPTIONS] [NATIVE]
Native-tested examples
These examples were executed with LibreOffice Calc 25.2.3.2. In the results, ␠ explicitly represents one U+0020 space; the surrounding double quotes illustrate the returned text rather than being part of it.
| Formula | Observed text | Explanation |
|---|---|---|
=RIGHTB("office";3) |
"ice" |
Three ASCII characters. |
=RIGHTB("中国";1) |
"␠" |
Half a trailing two-byte character → space. |
=RIGHTB("中国";2) |
"国" |
Entire last ideograph. |
=RIGHTB("中国";3) |
"␠国" |
First included CJK character is incomplete. |
=RIGHTB("中国";4) |
"中国" |
Entire two-character string. |
=RIGHTB("中国") |
"␠" |
Default byte count is 1. |
=RIGHTB("中国";0) |
"" |
Zero width → empty string. |
=RIGHTB("中国";5) |
"中国" |
Requested width exceeds text. |
The first five follow LibreOffice’s official examples and were checked by native formula execution. The zero, omitted, and oversize cases were independently calculated and run natively. [LO-RIGHTB] [NATIVE]
Mixed single-byte and double-byte text
The text A中B uses four DBCS-style units in the tested Calc build: 1 for A, 2 for 中, and 1 for B.
| Formula | Result | Interpretation |
|---|---|---|
=RIGHTB("A中B";1) |
"B" |
Last ASCII character. |
=RIGHTB("A中B";2) |
"␠B" |
Half of 中 plus B becomes space plus B. |
=RIGHTB("A中B";3) |
"中B" |
Full Chinese character and B. |
=RIGHTB("A中B";4) |
"A中B" |
Whole string. |
All four are actual Calc 25.2.3.2 observations. The RIGHTB(...;2) result is not the same as RIGHT("A中B";2) (which works in characters). Choose the function to match the specification you are validating. [NATIVE] [LO-RIGHTB]
A hands-on cell-reference example
Put the literal text 中A in cell J2. Elsewhere enter:
=RIGHTB(J2;1)
Observed native result: A. By contrast, =RIGHTB("中A";2) returned ␠A, where ␠ is an actual space. A three-unit request for this example returned 中A. These outcomes follow the directional byte-count rule and were tested in Calc 25.2.3.2. [NATIVE]
Advanced usage
ASCII suffix validation
For a code ending in a three-letter ASCII suffix, byte and character count produce the same selection when the suffix is entirely ASCII:
=IF(RIGHTB("中ABC";3)="ABC";"OK";"CHECK")
Native-tested result: OK. If the suffix might contain East Asian or combining characters, be explicit about whether the rule concerns characters (use RIGHT) or DBCS byte units (potentially RIGHTB). [NATIVE]
Combining RIGHTB with LENB
LENB estimates DBCS byte width, while RIGHTB selects a suffix using that width. For 中国, native Calc returned 国 from =RIGHTB("中国";2) and 2 from =LENB(RIGHTB("中国";2)). A half-character selection can introduce spaces, so the measured result may not represent the original text’s byte sequence. [LO-RIGHTB] [LO-LENB] [NATIVE]
Fractions and typed arguments
In Calc 25.2.3.2, =RIGHTB("中国";2.9) returned 国, while =RIGHTB("中国";1.9) returned a space. Both observations are consistent with truncating a fractional byte count to its integer part. =RIGHTB(12345;2) returned 45 because the numeric argument was converted to text in the tested setup. These are implementation observations, not unconditional guarantees for every locale or release. [NATIVE]
Why RIGHTB cannot validate UTF-8 file bytes
In a UTF-8 export, the number of encoded bytes for non-ASCII characters depends on Unicode code points. Calc’s DBCS-style substitution rule is not a UTF-8 encoder. For a strict external byte limit, validate the encoded output with that external format; use RIGHTB only when you know the receiving application expects compatible DBCS-width behavior. This distinction follows from comparing documented DBCS behavior with the concept of encoding, not from a live export test in the saved test. [LO-RIGHTB]
Errors, limits, and troubleshooting
| Case | Calc 25.2.3.2 observed result | Interpretation / fix |
|---|---|---|
=RIGHTB("中国";-1) |
Err:502 |
Byte count must not be negative. |
=RIGHTB("中国";"abc") |
#VALUE! |
Supply a numeric count. |
=RIGHTB() |
Err:511 |
Required text missing. |
=RIGHTB("x";1/0) |
#DIV/0! |
Upstream error propagates. |
| A right-side CJK character becomes blank-looking | An incomplete character was replaced by " ". |
Increase byte width or use RIGHT. |
| Formula fails after importing from another spreadsheet | English name, argument separator or engine differs. | Check Calc Formula options and retest with the Calc version in use. |
The table’s error strings are explicitly native 25.2.3.2 observations. They may render differently in localized Calc. [NATIVE] [LO-OPTIONS]
Compatibility and migration notes
LibreOffice Calc officially supports RIGHTB since 4.2. Google Sheets documents its separate RIGHTB(string, num_of_bytes) function. Microsoft describes RIGHTB as deprecated in its current Excel RIGHT documentation. Those claims are supported by their official websites; no Google Sheets or Excel formulas were executed in the saved test, so unusual Unicode and locale behavior must be checked independently before migration. [LO-RIGHTB] [GOOGLE-RIGHTB] [MS-RIGHT]
Related Calc pages
Official references and validation provenance
Documentation links verified 2026-10-12. The Help banner displayed LibreOffice 26.8. Formulas were natively executed in LibreOffice Calc 25.2.3.2 on Linux.
- [LO-RIGHTB] LibreOffice Calc RIGHTB Help: version availability, arguments/default, and DBCS replacement-space examples.
- [LO-LENB] LibreOffice Calc LENB Help: companion byte-width function.
- [LO-OPTIONS] LibreOffice Formula Options: separators, localized names.
- [GOOGLE-RIGHTB] Google Sheets RIGHTB Help: documented counterpart only.
- [MS-RIGHT] Microsoft Excel RIGHT Help: deprecation note for RIGHTB.
- [NATIVE] Saved LibreOffice Calc 25.2.3.2 Linux test records dated 2026-10-12. The preserved script, ODS cached results, and per-formula results agree for the cited cases. This review did not rerun Calc.