Skip to content
Advertisement

Trim from String after decimal places to 18 places in java – roundoff not required)

I am working on a legacy code where i have String field which hold some amount value, which should have only 18 char after decimal place, not more than that.

I have achieved this like below –

JavaScript

Is there any better way to do this ?

Advertisement

Answer

Use regex for a one line solution:

JavaScript

See live demo.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement