On Sat, 22 May 2010 07:51:31 am Alan Gauld wrote: > "Neven Gorsic" <neven.gor...@gmail.com> wrote > > > I run into Python error in rounding and not know how to predict > > when it will > > occur in order to prevent wrong result. > > It depends how you define wrong. When I was at scvhool the rules f > or rounding decimals said that if it ended in 5 you rounded to the > nearest even digit. > So 0.45 -> 0.4 and 0.55 ->0.6
That's called banker's rounding, and if you perform many calculations, on average it leads to the smallest rounding error. > But you seem to assume a 5 always rounds up... That's how I was taught to do rounding in school too. -- Steven D'Aprano _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor