npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-localized-numbers

v2.0.1

Published

library to localize numbers and currency with angular

Downloads

214

Readme

ngx-localized-numbers

library to localize numbers and currency with angular

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:

npm install ngx-localized-numbers --save

Usage

Import into application

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

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:

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

Shared module

If you are using a SharedModule 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):

@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:

<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.

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

or combine both pipes:

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

Define additional locales

You also may add or overwrite locales to the service:

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)