0

I have lightning-formatted-number with currency type and if value has more than 15 digits then it doesn't work (left is work, right not):

enter image description here

I show it with a wired method and I have 100 fields, so I don't want to have 100 getters. Is there a way to avoid this without getter?

1 Answer 1

0

Are all of those digit significant? If not, can you modify the values when generated? You mentioned "a wired method"; if the values are being computed in Apex, you can use Decimal.setScale(). Like Decimal.round(), it supports eight different rounding models, but unlike round() it allows you to round to a specified number of decimal places.

The method returns a new Decimal, so you'll need to apply it to your calculated value and store the result. Here's an example pulled from one of my projects:

this.tx.Local_Amount__c = (Math.abs(writeoff.Local_Amount__c) * guarantor.Guarantee_Percentage__c / 100.0).setScale(2, LoanUtil.RoundingMode);

In this case, LoanUtil.RoundingMode is a centralized constant to allow all rounding code in the system to use the same value, which can be changed if needed. In practice, we only ever use RoundingMode.HALF_EVEN, as this is the most common for financial transactions. If you expect lots of values ending in '999...' which you don't want rounded up, consider RoundingMode.FLOOR.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.