# ngx-localized-numbers

> library to localize numbers and currency with angular

Latest version **2.0.1** (published 2022-03-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install ngx-localized-numbers
pnpm add ngx-localized-numbers
yarn add ngx-localized-numbers
bun add ngx-localized-numbers
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2022-03-16 |
| First published | 2017-05-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16 |
| Dependencies | 1 |
| Unpacked size | 135 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Moritz Benzenhöfer |
| Maintainers | mbenzenhoefer |
| Keywords | localize, numbers, currency, i18n, amount |

## Links

- npm: https://www.npmjs.com/package/ngx-localized-numbers
- Repository: https://github.com/mbenzenhoefer/ngx-localized-numbers
- Issues: https://github.com/mbenzenhoefer/ngx-localized-numbers/issues
- npm.io page: https://npm.io/package/ngx-localized-numbers

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.3.0

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2022-03-16
- 1.0.0 — 2022-01-04
- 0.5.2 — 2022-01-03
- 0.4.1 — 2021-10-25
- 0.5.1 — 2021-10-25
- 0.5.0 — 2021-10-12
- 0.4.0 — 2021-10-12
- 0.3.1 — 2020-07-17
- 0.3.0 — 2019-09-27
- 0.2.0 — 2019-03-27
- 0.1.1 — 2018-09-21
- 0.1.0 — 2018-07-24
- 0.0.5 — 2017-05-24
- 0.0.4 — 2017-05-23
- 0.0.3 — 2017-05-22
- … 2 more at https://npm.io/package/ngx-localized-numbers/versions

## README

# ngx-localized-numbers

library to localize numbers and currency with angular

- [Supported Locales](#supported-locales)
- [Installation](#installation)
- [Usage](#usage)
- [Define additional locales](#define-additional-locales)

## Compatible versions with angular
- `>= 2.0.0`: angular 12/13
- `>= 1.0.0 & < 2.0.0`: angular 11
- `>= 0.4.0 & < 1.0.0`: angular 10
- `0.3.1`: angular 7-9

## Supported Locales

The following locales are currently supported by ngx-localized-numbers:

- cs_CZ
- da_DK
- de_AT
- de_CH
- de_DE
- de_LU
- el_GR
- en_AU
- en_CA
- en_GB
- en_HK
- en_IE
- en_IN
- en_MY
- en_NZ
- en_TH
- en_US
- en_ZA
- es_AR
- es_CO
- es_ES
- fi_FI
- fr_BE
- fr_CA
- fr_CH
- fr_FR
- fr_LU
- ga_IE
- hu_HU
- is_IS
- it_CH
- it_IT
- ja_JP
- ko_KR
- nl_BE
- nl_NL
- no_NO
- pl_PL
- pt_BR
- pt_PT
- ro_RO
- ru_RU
- sk_SK
- sv_SE
- th_TH
- tr_TR
- zh_CN
- zh_HK
- zh_TW

## Installation

First you need to install the npm module:

```sh
npm install ngx-localized-numbers --save
```

## Usage

### Import into application

First you need to import the module as forRoot() into your parent module:

```ts
import { NgxLocalizedNumbers } from 'ngx-localized-numbers';
@NgModule({
  imports: [
    // ...
    NgxLocalizedNumbers.forRoot()
  ]
  // ...
})
export class AppModule {}
```

If using submodules you may need to include the module there as well:

```ts
import { NgxLocalizedNumbers } from 'ngx-localized-numbers';
@NgModule({
  imports: [
    // ...
    NgxLocalizedNumbers
  ]
  // ...
})
export class AnyOtherModule {}
```

### Shared module

If you are using a [`SharedModule`](https://angular.io/docs/ts/latest/guide/ngmodule.html#!#shared-modules)
which is imported into different other application modules, you may export it from here so you do not need to import it in every child module.

### Set the locale

The locale can be set as follows (and anywhere else as well):

```ts
@Component({
  // ...
})
export class AppComponent implements OnInit {
  constructor(private localizedNumbersService: NgxLocalizedNumbersService) {}

  ngOnInit() {
    this.localizedNumbersService.setLocale('de_DE');
  }
}
```

That's it, now you can use the localization.

### Format numbers and amounts

There are two pipes included in this modules you may use (also chained usage is possible). These samples use the de_DE as locale:

#### formatNumber - Pipe

This pipe formats numbers with thousand separator and decimal separator from the locale. As a parameter, the amount of decimals can be provided:

```ts
<p>{{1000 | formatNumber:3 | formatCurrency}}</p> - prints 1.000,000 €

<p>{{1000 | formatNumber:2}}</p> - prints 1.000,00

<p>{{1000.47 | formatNumber:2}}</p>

<p>{{1000.47 | formatNumber:1}}</p>

<p>{{1000.9 | formatNumber}}</p>

<p>{{1000.1 | formatNumber:5}}</p>
```

#### formatCurrency - Pipe

This pipe will add the locales' currency to the number.

```ts
<p>{{1000 | formatCurrency}}</p> - prints 1000 €
```

or combine both pipes:

```ts
<p>{{1000 | formatNumber:2 | formatCurrency}}</p> - prints 1.000,00 €

```

## Define additional locales

You also may add or overwrite locales to the service:

```ts
this.localizedNumbersService.addLocale('en_US', {
  thousandSeparator: ',',
  decimalSeparator: '.',
  whitespaceBeforeCurrency: true,
  currency: '$'
});
```

**feel free to add missing locales via a PR, thanks!** (see src/locales.config.ts)

---
_Source: https://npm.io/package/ngx-localized-numbers · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
