Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→string-remove-thousand-separatorsnext

string-remove-thousand-separators7.2.5

Detects and removes thousand separators (dot/comma/quote/space) from string-type digits

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • API — REMSEP()
  • CONVERT DECI…
  • PAD POSITIVE…
  • API — DEFAULTS
  • API — VERSION
  • Changelog

No 3rd party dependencies. All dependencies and devDependencies, checked recursively, are Codsen packages.

Permalink to InstallationInstallation

Permalink to Quick TakeQuick Take

Permalink to ExamplesExamples

  • Convert decimal commas while retaining grouping separators
  • Pad a single decimal digit while removing thousand separators
  • Leave a single decimal place unpadded
  • Convert a comma decimal separator to a dot
  • Remove spaced thousand separators when no decimal separator is present
  • Keep thousand separators while still normalising the outer quotes
  • Leave a value unchanged when it contains non-numeric text
  • Preserve a number whose separators are ambiguous
  • Pad one-digit fractions without losing precision
  • Remove spaces used as thousand separators
  • Remove apostrophes used as thousand separators

API — remSep()

The main function remSep() is imported like this:

The function takes a string and an optional options object:

Input argumentTypeObligatoryDescription
str
Type: String
Obligatory: yes
strStringyesInput to work upon.
opts
Type: Plain object
Obligatory: no
optsPlain objectnoOptional Options Object.

None of the input arguments will be mutated by this program, we have unit tests to prove that.

The Optional Options Object has the following shape:

KeyTypeDefaultDescription
removeThousandSeparatorsFromNumbers
Type: Boolean
Default: true
removeThousandSeparatorsFromNumbersBooleantrueShould remove thousand separators? 1,000,000 → 1000000? Or Swiss-style, 1'000'000 → 1000000? Or Russian-style, 1 000 000 → 1000000?
padSingleDecimalPlaceNumbers
Type: Boolean
Default: true
padSingleDecimalPlaceNumbersBooleantruePad one decimal place numbers with zero? 100.2 → 100.20?
forceUKStyle
Type: Boolean
Default: false
forceUKStyleBooleanfalseConvert decimal commas to dots independently of grouping removal. With default padding, 1,5 → 1.50; 1,50 → 1.50.

Here are all defaults in one place for copying:

The function returns the formatted value as a string.

Convert decimals while keeping grouping

Set forceUKStyle: true to convert a decimal comma even when removeThousandSeparatorsFromNumbers is false. Grouping characters remain in place:

import { remSep } from "string-remove-thousand-separators";

remSep("1 234,50", {
  removeThousandSeparatorsFromNumbers: false,
  forceUKStyle: true,
});
// => "1 234.50"

padSingleDecimalPlaceNumbers independently controls whether a single fractional digit gains a trailing zero. It does not change a two-digit fraction.

Pad positive fractions below one

The default padding option also applies to unsigned fractions below one: 0.5 becomes 0.50, and .5 becomes .50. Set padSingleDecimalPlaceNumbers: false to retain a single fractional digit. Existing leading zeros and every fractional digit are preserved; grouping removal does not remove the decimal separator in these fractions.

import { remSep } from "string-remove-thousand-separators";

remSep("0.5"); // => "0.50"
remSep(".5", { padSingleDecimalPlaceNumbers: false }); // => ".5"
remSep("0,075", { forceUKStyle: true }); // => "0.075"

For these recognized fractions, surrounding whitespace and wrapping double quotes are removed before formatting, just as for other recognized numbers. Fractional digits are kept as text, including values too small for JavaScript’s numeric representation.

API — defaults

You can import defaults:

It's a plain object:

The main function calculates the options to be used by merging the options you passed with these defaults.

API — version

You can import version:

Permalink to changelogChangelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab