格式化浮点数而不AngularJS precision损失 [英] Formatting floating-point numbers without loss of precision in AngularJS

查看:215
本文介绍了格式化浮点数而不AngularJS precision损失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在AngularJS如何在HTML页面中做I输出一个浮点数,而不precision的损失和避免不必要的填充与0?

In AngularJS how do I output a floating point number on an HTML page without loss of precision and without unnecessary padding with 0's?

我认为是数字NG-过滤器( https://开头的文档。 angularjs.org/api/ng/filter/number ),但fractionSize参数导致固定数量的小数位数:

I've considered the "number" ng-filter (https://docs.angularjs.org/api/ng/filter/number) but the fractionSize parameter causes a fixed number of decimals:

{{ number_expression | number : fractionSize}}

我在寻找各种其他语言的东西被称为精确的重现,规范化字符串重新presentation,再版,往返等,但我一直没能找到任何东西类似的AngularJS。

I'm looking for what in various other languages is referred to as "exact reproducibility", "canonical string representation", repr, round-trip, etc. but I haven't been able to find anything similar for AngularJS.

例如:


  • 1 =>1

  • 1.2 =>1.2

  • 1.23456789 =>1.23456789

推荐答案

我偶然发现了一个明显的解决方案喽!完全删除使用数字NG-过滤器会导致AngularJS根据我的要求除权pression简单地转换为字符串。

I stumbled upon an obvious solution myself! Completely removing the use of the "number" ng-filter will cause AngularJS to simply convert the expression to a string according to my requirements.

所以

{{ number_expression }}

而不是

{{ number_expression | number : fractionSize}}

这篇关于格式化浮点数而不AngularJS precision损失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆