使用角度4中的十进制管道进行四舍五入 [英] Block Round Off using decimal pipe in angular 4
本文介绍了使用角度4中的十进制管道进行四舍五入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用角度4,
{{31.94 | number:'1.0-0'}}
输出:32
任何想法,如何阻止四舍五入.预期结果为31
Any idea, how to block the round off. Expecting the result is 31
推荐答案
您需要创建自定义管道,因为DecimalPipe不提供任何楼层特征.另外,您可以在其中添加十进制管道. 您的自定义管道:
You need to create your custom pipe as DecimalPipe doesn't provide any floor feature. Plus you can add your decimal pipe in it. Your Custom Pipe:
@Pipe({name: 'floor'})
export class FloorPipe implements PipeTransform {
/**
*
* @param value
* @returns {number}
*/
transform(value: number): number {
return Math.floor(value);
}
}
在模板中用作:
<span>{{ yournumber | floor | your_decimal_pipe }}</span>
这篇关于使用角度4中的十进制管道进行四舍五入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文