Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 将mat表格中的小数点限制为2位_Angular_Angular Material_Angular Pipe_Mat Table - Fatal编程技术网

Angular 将mat表格中的小数点限制为2位

Angular 将mat表格中的小数点限制为2位,angular,angular-material,angular-pipe,mat-table,Angular,Angular Material,Angular Pipe,Mat Table,我想使用十进制管道来限制我的mat表中的十进制数。你能告诉我怎么做吗 我的桌子: 我的代码: // html <ng-container [matColumnDef]="column.attribute"> <mat-header-cell id="custom-header-cell" *matHeaderCellDef> <div> {{ column.name }}

我想使用十进制管道来限制我的mat表中的十进制数。你能告诉我怎么做吗

我的桌子:

我的代码:

// html
 <ng-container [matColumnDef]="column.attribute">
            <mat-header-cell id="custom-header-cell" *matHeaderCellDef>
              <div>
                {{ column.name }}
              </div>
            </mat-header-cell>
            <mat-cell id="custom-content-cell" *matCellDef="let row">
              <span class="mobile-label">{{column.mobile}}</span>
              {{ column.object !== null ? row[column.object][column.attribute] : row[column.attribute] }}
            </mat-cell>
          </ng-container>

// ts
  private monthColumns = [
    { attribute: '1', name: 'Januar', mobile: 'Januar:', object: 'values' },
    { attribute: '2', name: 'Februar', mobile: 'Februar:', object: 'values' },
    { attribute: '3', name: 'März', mobile: 'März:', object: 'values' },
    { attribute: '4', name: 'April', mobile: 'April:', object: 'values' },
    { attribute: '5', name: 'Mai', mobile: 'Mai:', object: 'values' },
    { attribute: '6', name: 'Juni', mobile: 'Juni:', object: 'values' },
    { attribute: '7', name: 'Juli', mobile: 'Juli:', object: 'values' },
    { attribute: '8', name: 'August', mobile: 'August::', object: 'values' },
    { attribute: '9', name: 'September', mobile: 'September:', object: 'values' },
    { attribute: '10', name: 'Oktober', mobile: 'Oktober:', object: 'values' },
    { attribute: '11', name: 'November', mobile: 'November:', object: 'values' },
    { attribute: '12', name: 'Dezember', mobile: 'Dezember:', object: 'values' }
  ];
//html
{{column.name}
{{column.mobile}}
{{column.object!==null?行[column.object][column.attribute]:行[column.attribute]}
//ts
私人每月专栏=[
{attribute:'1',name:'Januar',mobile:'Januar:',object:'values'},
{attribute:'2',name:'Februar',mobile:'Februar:',object:'values'},
{attribute:'3',name:'März',mobile:'März:',object:'values'},
{attribute:'4',name:'April',mobile:'April:',object:'values'},
{attribute:'5',name:'Mai',mobile:'Mai:',object:'values'},
{attribute:'6',name:'Juni',mobile:'Juni:',object:'values'},
{attribute:'7',name:'Juli',mobile:'Juli:',object:'values'},
{attribute:'8',name:'August',mobile:'August::',object:'values'},
{attribute:'9',name:'septer',mobile:'septer:',object:'values'},
{属性:'10',名称:'Oktober',移动:'Oktober:',对象:'values'},
{属性:'11',名称:'11',移动:'11:',对象:'values'},
{属性:'12',名称:'Dezember',移动:'Dezember:',对象:'values'}
];

您可以使用内置管道。试试下面的方法


{{column.mobile}}
{{column.object!==null?行[column.object][column.attribute]:行[column.attribute]|编号:'1.1-2'}
编号:“1.1-2”
-说明

从文档中:

{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}

  • 最小整数位数
    :小数点前的最小整数位数。默认值为1
  • minFractionDigits
    :小数点后的最小位数。默认值为0
  • maxFractionDigits
    :小数点后的最大位数。默认值为3

因此,在这种情况下,显示小数点前至少1位数字。小数点后最少1位,最多2位。

您是否尝试使用
toFixed()
?否,我如何在该上下文中使用它?我又想到了一个补充问题。。。如何处理单个列并使用管道转换它们?不幸的是,我不确定如何将数据呈现为列。您可以在此处引用:。我已经将管道应用于重量列。嘿,谢谢你的示例。在您的代码中,每一列都用html单独寻址。我以不同的方式构建html,并在ng容器中调用表。。。您知道在这种情况下是否有一种简单的方法来转换列吗?我以前没有在
ng container
中使用material table。恐怕我不能再帮你了。