View source | Discuss this page | Page history | Printable version   

POS - Round to nearest 5 cents

Code snippet

Name: POS - Round to nearest 5 cents
Version: POS/2.20 & 2.30 Beta
Author: ronny_g and slingshotpk

This code was created using MySQL in Windows.

This script will allow you to round to the nearest 5 cents when completing a sale. It rounds up and down. For rounding down only, uncomment the two lines in the center of the script.

1) Add Event to the Ticket.Buttons Resource

Add the following event to the Ticket.Buttons resource:

<event key="" code=""/>

2) Create the Resource

Create a text resource called and add the following to it:

import com.openbravo.format.Formats; 
import com.openbravo.pos.ticket.TicketLineInfo; 
import com.openbravo.pos.ticket.TicketProductInfo;  
import java.util.Properties; 
total = ticket.getTotal();  
if (total > 0.0) {  
  //rounding m to nearest multiple of n  
  n=5.0; //round to the nearest 5cents  
  d = Math.floor((m*100.0+n/2.0)/n)*n/100.0-m;  
  //round to 2 decimal places 
  rounding = Math.round(d * Math.pow(10, (double) 2)) / Math.pow(10,(double) 2); 
  //add line if rounding is needed 
  if (rounding <= -0.01 || rounding >= 0.01) {  
    taxes = ticket.getTaxLines();  
    for (int i = 0; i < taxes.length; i++) {  
      taxline = taxes[i];  
      // if you only want to round down, remove slashes from the next two lines
      //     if (rounding>0) {
      //       rounding = rounding - .05; }
        new TicketLineInfo( 
        "Rounding adjustment",  
  sales.setSelectedIndex(ticket.getLinesCount() - 1); 
 } else {  

That should be it. You can obviously change anything you wish to suit your setup. Let me know if something is not working or something can be done better.

Good Luck, Ronny G

Retrieved from ""

This page has been accessed 15,385 times. This page was last modified on 19 April 2010, at 22:32. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.