4

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;
1
  • 1
    Javascript doesn't type variables : it only knows strings and numbers. If you want a BigDecimal in your back-end, consider parsing it in Java once you receive it. Commented Aug 29, 2018 at 11:37

1 Answer 1

7

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)
Sign up to request clarification or add additional context in comments.

1 Comment

You can add the TypeScript definition too, according its docs: github.com/MikeMcl/big.js/#typescript

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.