Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cast number type to BigDecimal TypeScript ( Angular)

I need to send a BigDecimal value from my angular front-end part to the java back-end. I tried to find a valuable solution but it seems that TypeScript knows only number type.

Is there any way to declare/cast a BigDecimal attribute in my angular project?

private totalPrice: number;
like image 204
Vlad Danila Avatar asked Oct 25 '25 10:10

Vlad Danila


1 Answers

After couple of libraries tried, big.js seems the best:

Install the library using the following command in root folder:

$ npm install --save big.js

Import:

import Big from 'big.js';

Use:

private totalPrice: any;
this.totalPrice = Big(number_value).toPrecision(2) --> (e.g. 15.00)
like image 185
Vlad Danila Avatar answered Oct 28 '25 01:10

Vlad Danila



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!