#!/usr/local/bin/python # coding: iso-8859-1 # Copyright © 2009 by Amos Newcombe # # This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with this program. If not, see . import math def round(x): 'round x to nearest integer; if two nearest integers, use the even one' xN = math.floor(x) xF = x - xN if xF < 0.5 : pass # round down elif xF > 0.5 : xN += 1 # round up elif xN % 2 == 0.0: pass # round down to even number else : xN += 1 # round up to even number return int(xN)