What are the parameters for the number Pipe - Angular 2

前端 未结 4 2119
陌清茗
陌清茗 2020-12-04 11:39

I have used the number pipe below to limit numbers to two decimal places.

{{ exampleNumber | number : \'1.2-2\' }}

I was wondering what the

相关标签:
4条回答
  • 2020-12-04 12:18
    1. Regarding your first question.The pipe works as follows:

      numberValue | number: {minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}

      • minIntegerDigits: Minimum number of integer digits to show before decimal point,set to 1by default
      • minFractionDigits: Minimum number of integer digits to show after the decimal point

      • maxFractionDigits: Maximum number of integer digits to show after the decimal point

    2.Regarding your second question, Filter to zero decimal places as follows:

    {{ numberValue | number: '1.0-0' }}
    

    For further reading, checkout the following blog

    0 讨论(0)
  • 2020-12-04 12:19

    From the DOCS

    Formats a number as text. Group sizing and separator and other locale-specific configurations are based on the active locale.

    SYNTAX:

    number_expression | number[:digitInfo[:locale]]

    where expression is a number:

    digitInfo is a string which has a following format:

    {minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}
    
    • minIntegerDigits is the minimum number of integer digits to use.Defaults to 1
    • minFractionDigits is the minimum number of digits
    • after fraction. Defaults to 0. maxFractionDigits is the maximum number of digits after fraction. Defaults to 3.
    • locale is a string defining the locale to use (uses the current LOCALE_ID by default)

    DEMO

    0 讨论(0)
  • 2020-12-04 12:21

    The parameter has this syntax:

    {minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}

    So your example of '1.2-2' means:

    • A minimum of 1 digit will be shown before decimal point
    • It will show at least 2 digits after decimal point
    • But not more than 2 digits
    0 讨论(0)
  • 2020-12-04 12:31

    '1.0-0' will give you zero decimal places i.e. no decimals. e.g.$500

    0 讨论(0)
提交回复
热议问题