(Math.round(doubleValue*100))/100.0
Is there a better way to round decimals to two decimal places?
DecimalFormat format=new DecimalFormat("#.##"); System.out.println(format.format(doubleValue));
If you are interested in decimals and therefore exact decimal values, you should usually use java.math.BigDecimal . You can then use Decimal.round or Decimal.setScale to round to suit your exact needs.
java.math.BigDecimal
Decimal.round
Decimal.setScale
Source: https://habr.com/ru/post/891459/More articles:Is joining on FK faster than joining without FK? - performanceiOS Augmented Reality with Compass and Location - iosenum in the constructor - how? - enumsWhat is the right way for Object Orient for an Android program? - androidMySQL / InnoDB Plugin: Will NULL Values ββfor VARCHAR Fields Occupy Storage Space? - nullWhat aspects can we touch upon? Unit Testing ASP.NET MVC Views - unit-testingUsing OpenCL in a guest system with a processor on Virtual Box, VMWare or Parallels? - virtualizationEntity Framework IValidatableObject reference DbContext - validationCreating a list of Anchor tags - javascriptConfigure Add / Edit dialog in jqGrid - javascriptAll Articles