将数字类型转换为 BigDecimal TypeScript(Angular)

Vla*_*ila 3 casting numbers bigdecimal typescript angular

我需要从我的角度前端部分向 java 后端发送一个BigDecimal值。我试图找到一个有价值的解决方案,但似乎TypeScript只知道数字类型。

有什么方法可以在我的 angular 项目中声明/转换BigDecimal属性?

private totalPrice: number;
Run Code Online (Sandbox Code Playgroud)

Vla*_*ila 5

在尝试了几个库之后,big.js似乎是最好的:

在根文件夹中使用以下命令安装库:

$ npm install --save big.js

进口:

从“big.js”导入大;

用:

private totalPrice: any;
this.totalPrice = Big(number_value).toPrecision(2) --> (e.g. 15.00)
Run Code Online (Sandbox Code Playgroud)

  • 您也可以根据其文档添加 TypeScript 定义:https://github.com/MikeMcl/big.js/#typescript (2认同)