Search code examples
angulartypescriptcastingnumbersbigdecimal

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;

Solution

  • 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)