Skip to content
Advertisement

Numpy rounding issue

Can someone explain to me why is numpy round acting strange with this exact number rounding:

JavaScript

It’s obvious that the first number is not rounded well, any ideas?

EDIT: Since I’m focused here on the precision, not so much on the performance, I’ve used python round function to solve this problem:

JavaScript

Advertisement

Answer

Check the small print 2 in the documentation of round aka around. The short answer is that round “uses a fast but sometimes inexact algorithm” and to use format_float_positional if you want to see the correct result.

enter image description here

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement