【发布时间】:2018-11-09 13:37:30
【问题描述】:
我会立即承认我是一名 java 开发人员,并且正在寻找类似于 DecimalFormat 的函数,类似于:
DecimalFormatSymbols unusualSymbols = new DecimalFormatSymbols(Locale.getDefault());
unusualSymbols.setDecimalSeparator('|');
unusualSymbols.setGroupingSeparator('^');
DecimalFormat weirdFormatter = new DecimalFormat("#,##0.###", unusualSymbols);
Number myNum = weirdFormatter.parse("8^453|13");
代码改编自Oracle javase i18n
我能找到的与此相关的每个资源要么只是格式化(而不是解析)
How to specify thousand separator for number pipe in Angular 4
NativeScript: Formatting number typescript
或者人们使用正则表达式来替代(这对我来说似乎很疯狂)
How can I parse a string with a comma thousand separator to a number?
或一些不考虑国际化的一般性话题
TypeScript Converting a String to a number
In Typescript, How to check if a string is Numeric
我在 Angular 的 GitHub 上进行了一些挖掘,并且确实找到了这个类 format_number,但这似乎只与格式化而不是解析有关,或者至少我不知道如何使用它。
问题是:Angular 中有这样的对象吗?如果没有,这也是一个有效的答案(我可以停止搜索)。如果您想使用外部库传递解决方案,请记住add context around the link
【问题讨论】:
标签: angular typescript parsing internationalization numbers