Is there a way to round numbers into a reader friendly format? (e.g. $1.1k) [closed]

Here is a simple function to do it: function abbrNum(number, decPlaces) { // 2 decimal places => 100, 3 => 1000, etc decPlaces = Math.pow(10, decPlaces); // Enumerate number abbreviations var abbrev = [“k”, “m”, “b”, “t”]; // Go through the array backwards, so we do the largest first for (var i = abbrev.length – …

Read more

Regex currency validation

The RegEx // Requires a decimal and commas ^\$?(([1-9]\d{0,2}(,\d{3})*)|0)?\.\d{1,2}$ // Allows a decimal, requires commas (?=.*\d)^\$?(([1-9]\d{0,2}(,\d{3})*)|0)?(\.\d{1,2})?$ // Decimal and commas optional (?=.*?\d)^\$?(([1-9]\d{0,2}(,\d{3})*)|\d+)?(\.\d{1,2})?$ // Decimals required, commas optional ^\$?(([1-9]\d{0,2}(,\d{3})*)|0)?\.\d{1,2}$ // *Requires/allows X here also implies “used correctly” The RegEx Breakdown When the optional parts are too liberal, we need to look ahead and guarantee there’s a …

Read more

How to display the currency symbol to the right in Angular

Since Angular2 RC6 version you can set default locale directly in your app module (providers): import {NgModule, LOCALE_ID} from ‘@angular/core’; @NgModule({ providers: [{ provide: LOCALE_ID, useValue: ‘de-DE’ // ‘de-DE’ for Germany, ‘fr-FR’ for France … }, ] }) Afterwards the currency pipe should pick up the locale settings and move the symbol to right: @Component({ …

Read more

Is there a functionality in JavaScript to convert values into specific locale formats?

I found a way to do this at this page. You can you toLocaleString without using toFixed before it. toFixed returns a string, toLocaleString should get a number. But you can pass an options object with toLocaleString, the option minimumFractionDigits could help you with the functionality toFixed has. 50.toLocaleString(‘de-DE’, { style: ‘currency’, currency: ‘EUR’, minimumFractionDigits: …

Read more