Class InvoiceServices


public class InvoiceServices extends Object
InvoiceServices - Services for creating invoices

Note that throughout this file we use BigDecimal to do arithmetic. It is critical to understand the way BigDecimal works if you wish to modify the computations in this file. The most important things to keep in mind:

Critically important: BigDecimal arithmetic methods like add(), multiply(), divide() do not modify the BigDecimal itself. Instead, they return a new BigDecimal. For example, to keep a running total of an amount, make sure you do this:

amount = amount.add(subAmount);

and not this,


Use .setScale(scale, roundingMode) after every computation to scale and round off the decimals. Check the code to see how the scale and roundingMode are obtained and how the function is used.

use .compareTo() to compare big decimals

ex. (amountOne.compareTo(amountTwo) == 1) checks if amountOne is greater than amountTwo

Use .signum() to test if value is negative, zero, or positive

ex. (amountOne.signum() == 1) checks if the amount is a positive non-zero number

Never use the .equals() function becaues it considers 2.0 not equal to 2.00 (the scale is different) Instead, use .compareTo() or .signum(), which handles scale correctly.

For reference, check the official Sun Javadoc on java.math.BigDecimal.