Use below code to round off the total amount
#set($round = $ticket.roundDouble($ticket.getTotal(),0) - $ticket.getTotal()) <line> <text align="left" bold="true" length="12">Round Off</text> <text align ="right" length="36" bold="true">$ticket.formatCurrency($round)</text> </line> <line size="1"> <text align="left" bold="true" length="12">Total.</text> <text align ="right" length="36" bold="true">$ticket.formatCurrency($ticket.roundDouble($ticket.getTotal(),0))</text> </line>
Amount can be rounded in many ways.
To round the amount to nearest 0.25, use the below code
#set($round = $ticket.getTotal() / 0.25 ) #set($round = $ticket.roundDouble($round, 0) * 0.25) #set($roundoff = $round - $ticket.getTotal()) <line> <text align="left" bold="true" length="16">Round Off</text> <text align ="right" length="26" bold="true">$ticket.formatCurrency($roundoff)</text> </line> <line size="1"> <text align="left" bold="true" length="16">Total.</text> <text align ="right" length="26" bold="true">$ticket.formatCurrency($round)</text> </line>
To round the amount to nearest 5, use the below code
#set($round = $ticket.getTotal() / 5 ) #set($round = $ticket.roundDouble($round, 0) * 5) #set($roundoff = $round - $ticket.getTotal()) <line> <text align="left" bold="true" length="16">Round Off</text> <text align ="right" length="26" bold="true">$ticket.formatCurrency($roundoff)</text> </line> <line size="1"> <text align="left" bold="true" length="16">Total.</text> <text align ="right" length="26" bold="true">$ticket.formatCurrency($round)</text> </line>
The above scripts need to paste below the scripts for Total after the <!– TAXES END–> (It should be pasted exactly between the lines </line> and <line></line>
After pasting the script it should look like the one in the picture below:
Use below code in event.total to add round off as an item to the bill.
First create a product with barcode “roundoff”.
//ROUND OFF double step = 0.005; int decimals = 3; int numlines = ticket.getLinesCount(); for (int i=0;i<numlines;i++) { if(ticket.getLine(i).printCode()!=null && ticket.getLine(i).printCode().equals("roundoff")) { ticket.removeLine(i); } } double total = ticket.getTotal(); double round = total % step; if(round > 0 && ticket.roundDouble(round, decimals) < step) { //ALWAYS STEP DOWN sales.addItemByPrice("roundoff", round * -1); } Save & restart