Cast number type to BigDecimal TypeScript ( Angular)

12,098

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)
Share:
12,098
Vlad Danila
Author by

Vlad Danila

Technical University of Cluj-Napoca Computer Science student

Updated on June 04, 2022

Comments

  • Vlad Danila
    Vlad Danila almost 2 years

    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;
    
  • Alberto Sanchez Gonzalez
    Alberto Sanchez Gonzalez about 4 years
    You can add the TypeScript definition too, according its docs: github.com/MikeMcl/big.js/#typescript