If you target to modern browsers you can use:
new Intl.NumberFormat('en-us', {minimumFractionDigits: 2}).format(1234567.89)
or
(1234567.89).toLocaleString('en-us', {minimumFractionDigits: 2})
For browser support: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
Answer from HolgerJeromin on Stack Overflow Top answer 1 of 3
28
If you target to modern browsers you can use:
new Intl.NumberFormat('en-us', {minimumFractionDigits: 2}).format(1234567.89)
or
(1234567.89).toLocaleString('en-us', {minimumFractionDigits: 2})
For browser support: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
2 of 3
4
TypeScript is a superset of JavaScript meaning that what you can do in JavaScript can be done in TS as well (but not the other way around). That said look at this article.
Now talking in the context of NativeScript, you can either provide the data to your binding context in the right format or use valueConverter.
Here you can find examples on how to use value converters with data binding
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Intl › NumberFormat
Intl.NumberFormat - JavaScript - MDN Web Docs
In order to get the format of the language used in the user interface of your application, make sure to specify that language (and possibly some fallback languages) using the locales argument: ... const number = 123456.789; // German uses comma as decimal separator and period for thousands console.log(new Intl.NumberFormat("de-DE").format(number)); // 123.456,789 // Arabic in most Arabic speaking countries uses real Arabic digits console.log(new Intl.NumberFormat("ar-EG").format(number)); // ١٢٣٤٥٦٫٧٨٩ // India uses thousands/lakh/crore separators console.log(new Intl.NumberFormat("en-IN").format(number)); // 1,23,456.789 // the nu extension key requests a numbering system, e.g.
TutorialsPoint
tutorialspoint.com › typescript › typescript_number_tofixed.htm
TypeScript - Number toFixed()
This method formats a number with a specific number of digits to the right of the decimal. digits − The number of digits to appear after the decimal point. A string representation of number that does not use exponential notation and has the exact
Joshuaslate
joshuaslate.com › blog › currency-values-in-typescript
Working with Currency Values in TypeScript
November 28, 2022 - The cornerstone of our currency formatting will be Intl.NumberFormat.
Educative
educative.io › answers › what-is-the-numbertoprecision-method-in-typescript
What is the Number.toPrecision() method in TypeScript?
We can use the Number.toPrecision() method in TypeScript to format a number to a specified length. With this method, we can even add a decimal point or nulls to create the specified length.
Angular
v17.angular.io › api › common › formatNumber
formatNumber
Angular is a platform for building mobile and desktop web applications. Join the community of millions of developers who build compelling user interfaces with Angular.
Educative
educative.io › answers › what-are-numbers-in-typescript
What are numbers in TypeScript?
It doesn’t have different data types, like int, float, or double. Everything is simply a number in TypeScript.
typescriptlang.org
typescriptlang.org › docs › handbook › 2 › everyday-types.html
TypeScript: Documentation - Everyday Types
We’ll start by reviewing the most basic and common types you might encounter when writing JavaScript or TypeScript code. These will later form the core building blocks of more complex types. JavaScript has three very commonly used primitives: string, number, and boolean.
EDUCBA
educba.com › home › software development › software development tutorials › typescript tutorial › typescript number to string
TypeScript number to string | Learn the Examples and Primitive Types
April 5, 2023 - In typescript, Number to string is a method of conversion which is defined as converting the given number to string using the method provided number data type, which supports floating-point numbers such as decimal or hexadecimal or octal numbers.
Call +917738666252
Address Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
Tutlane
tutlane.com › tutorial › typescript › typescript-number-data-type
TypeScript Number Data Type - Tutlane
The TypeScript will support all numeric values same as JavaScript and it will store all the numbers as floating-point numbers.