[ADF-4713] Add new DecimalNumber Pipe to transform and localize numbers (#4926)

* [ADF-4713] Add new DecimalNumber Pipe to transform and localize numbers

* Unsubscribe from userPreference service

* Make Pipe impure

* Add documentation in localization page
This commit is contained in:
davidcanonieto
2019-07-18 11:09:50 +01:00
committed by Eugenio Romano
parent 8ee5cd1908
commit a0d4160c11
25 changed files with 457 additions and 66 deletions

View File

@@ -0,0 +1,53 @@
# [Decimal Number Pipe](../../../lib/core/pipes/decimal-number.pipe.ts "Defined in multi-value.pipe.ts")
Transforms a number to have a certain amount of digits in its integer part and also in its decimal part.
## Basic Usage
### Properties
| Name | Type | Default value | Description |
| ---------- | ---------------------------------------------------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------- |
| digitsInfo | [DecimalNumberModel](../../../lib/core/models/decimal-number.model.ts) | | A format to apply to the date value. [Date Pipe Formats.](https://angular.io/api/common/DatePipe#custom-format-options) |
| locale | string | 'en-US' | A locale id for the locale format rules to use. |
## Details
This pipe transforms a given number so it follows the set configuration for the pipe. You can change this configuration by changing the parameters in your `app.config.json`.
```json
"decimalValues": {
"minIntegerDigits": 1,
"minFractionDigits": 0,
"maxFractionDigits": 2
}
```
You can also overwrite this config by passing a [DecimalNumberModel](../../../lib/core/models/decimal-number.model.ts) as an argument for this pipe.
The number can be also localized so it applies commas and dots in the right place depending on the locale id in use.
#### Result
```ts
decimalNumberPipe.transform(1234.567);
//Returns '1,234.57'
decimalNumberPipe.transform(1234.567, digitsConfig, "it");
//Returns '1.234,57'
```
And now with a different config:
```ts
digitsConfig = {
minIntegerDigits: 6,
minFractionDigits: 4,
maxFractionDigits: 4
};
decimalNumberPipe.transform(1234.567, digitsConfig);
//Returns '001,234.5670'
```
More info: [Angular DecimalPipe](https://angular.io/api/common/DecimalPipe)

View File

@@ -10,6 +10,7 @@ Dates are not written the same around the world. That is where localizing a date
- [Adding language support](#adding-language-support)
- [Using the localized date pipe](#using-the-localized-date-pipe)
- [Using the time ago pipe](#using-the-time-ago-pipe)
- [Using the decimal number pipe](#using-the-decimal-number-pipe)
## Setting up the configuration in your app
@@ -71,4 +72,19 @@ Converts a recent past date into a number of days ago.
Usage of the [time ago pipe](../core/pipes/time-ago.pipe.md).
## Using the decimal number pipe
Localizes the punctuation marks of a given number.
<!-- {% raw %} -->
{{ number | adfDecimalNumber }}
<!-- {% endraw %} -->
`Input:` 1999.12
`Output (english locale):` 1,999.12
`Output (italian locale):` 1.999,12
Usage of the [decimal number pipe](../core/pipes/decimal-number.pipe.md).
Find more info about localization in the [Angular Docs](https://angular.io/guide/i18n#setting-up-the-locale-of-your-app).