填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫Home

PercentPipe

把數字轉換成百分比字串, 根據本地化規則進行格式化,這些規則會決定分組大小和分組分隔符、小數點字元以及其它與本地化環境有關的配置項。

Transforms a number to a percentage string, formatted according to locale rules that determine group sizing and separator, decimal-point character, and other locale-specific configurations.

{{ value_expression | percent [ : digitsInfo [ : locale ] ] }}
      
      {{ value_expression | percent [ : digitsInfo [ : locale ] ] }}
    

NgModule

輸入值

value string | number

引數

digitsInfo string
可選. 預設值是 `undefined`.
locale string
可選. 預設值是 `undefined`.

參見

使用說明

下列程式碼展示了該管道如何根據多種格式規範把數字轉換成文字字串, 這裡使用的預設語言環境是 en-US

The following code shows how the pipe transforms numbers into text strings, according to various format specifications, where the caller's default locale is en-US.

@Component({ selector: 'percent-pipe', template: `<div> <!--output '26%'--> <p>A: {{a | percent}}</p> <!--output '0,134.950%'--> <p>B: {{b | percent:'4.3-5'}}</p> <!--output '0 134,950 %'--> <p>B: {{b | percent:'4.3-5':'fr'}}</p> </div>` }) export class PercentPipeComponent { a: number = 0.259; b: number = 1.3495; }
      
      @Component({
  selector: 'percent-pipe',
  template: `<div>
    <!--output '26%'-->
    <p>A: {{a | percent}}</p>

    <!--output '0,134.950%'-->
    <p>B: {{b | percent:'4.3-5'}}</p>

    <!--output '0 134,950 %'-->
    <p>B: {{b | percent:'4.3-5':'fr'}}</p>
  </div>`
})
export class PercentPipeComponent {
  a: number = 0.259;
  b: number = 1.3495;
}