使用角度4中的十进制管道进行四舍五入

编程入门 行业动态 更新时间:2024-10-17 15:25:54
本文介绍了使用角度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中的十进制管道进行四舍五入

本文发布于:2023-11-10 02:45:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574127.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:角度   四舍五入   制管

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!