Skip to main content
v2026.11,858 entries · CC-BY 4.0
LAC HealthMedical & Research SuppliesReagents, PPE & instruments — chain-of-custody documented.Fast, traceable sourcing built for regulated research environments, from bench consumables to instrumentation.Shop lac.us CodeCASRAIlac.us

NumPy Round: np.round Syntax, Decimals and Half-to-Even

How np.round works: syntax, the decimals argument, half-to-even rounding, why it differs from Python round, and the NumPy 2.0 np.round_ removal.

Written and maintained by CASRAI Editorial Board

Last updated

numpy.round (also written np.round) rounds each element of an array to a chosen number of decimal places. It is a different rule from the one most people learn at school: values exactly halfway between two candidates go to the nearest even value, so np.round(2.5) returns 2.0, not 3.0. This guide covers the syntax, the half-to-even rule, why results can differ from Python’s built-in round, and a NumPy 2.0 change that breaks many older tutorials. The NumPy 2.5 manual is the reference for the signature and behaviour below.

What it is used for in research

Researchers use np.round when a computed array has to be reduced to a reporting precision, for example effect sizes to two decimals, p-values to three, or large counts to the nearest ten. The function returns a new array, so the original data stays at full precision unless you overwrite it. The practical rule for research reporting is to round for display and keep the unrounded values for any further calculation, because rounding intermediate results compounds error.

Install or access

NumPy is installed from the official project instructions at numpy.org/install. The page recommends starting with an environment-based method using conda or pip.

  • pip: pip install numpy
  • conda: conda create -n my-env, then conda activate my-env, then conda install numpy
  • Virtual environment: python -m venv my-env, then source my-env/bin/activate (macOS and Linux) or my-env\Scripts\activate (Windows)

Once installed, import numpy as np gives you np.round. For an introduction to the array type it operates on, see working with NumPy arrays.

Step-by-step: round an array

The signature is numpy.round(a, decimals=0, out=None). The argument a is any array_like, decimals is an integer (default 0), and out is an optional output array of the same shape.

  1. Import NumPy: import numpy as np
  2. Round to whole numbers with the default: np.round([0.37, 1.64]) returns array([0., 2.]). The result is still a float array.
  3. Round to a number of decimal places by setting decimals: np.round([0.37, 1.64], decimals=1) returns array([0.4, 1.6]).
  4. Round to the left of the decimal point with a negative decimals, which the manual defines as the number of positions to the left of the decimal point: np.round([1, 2, 3, 11], decimals=-1) returns array([ 0, 0, 0, 10]).
  5. Call it as a method if you prefer: a.round(decimals=2) on an ndarray is the equivalent form, and the method’s own page refers back to numpy.around for full documentation.

Why 2.5 rounds to 2.0

For values exactly halfway between two rounded decimal values, NumPy rounds to the nearest even value. The manual states that 1.5 and 2.5 both round to 2.0, and that -0.5 and 0.5 both round to 0.0. The documented example is np.round([.5, 1.5, 2.5, 3.5, 4.5]), which returns array([0., 2., 2., 4., 4.]).

Python’s built-in round follows the same convention: its documentation says ties go toward the even choice, so round(0.5) and round(-0.5) are 0 and round(1.5) is 2. If your reporting standard requires half-up rounding, neither function does that out of the box, so write the rule explicitly and test it on your own data rather than assuming the default matches.

Output and how to read it

The function returns an array of the same type as the input and a new array unless you pass out. What that means in practice:

Input Call Result
Float values np.round([0.37, 1.64]) Floats: array([0., 2.])
Integer values, positive decimals np.round([1, 2, 3, 11], decimals=1) Unchanged integers: array([ 1, 2, 3, 11])
Integer values, negative decimals np.round([1, 2, 3, 11], decimals=-1) array([ 0, 0, 0, 10])
Complex values np.round(z) Real and imaginary parts are rounded separately

When you supply out, it must be an ndarray of the same shape as the expected output, and values are cast to its type if necessary. Rounding a float gives a float, so use .astype(int) afterwards if you need integers.

np.round vs np.around vs ndarray.round vs built-in round

All three NumPy forms do the same job: numpy.around is an alias, and ndarray.round is the equivalent method. The one that behaves differently is Python’s built-in, and the difference is visible on real values. In the NumPy manual, np.round(16.055, 2) returns 16.06 while round(16.055, 2) returns 16.05, because 16.055 is stored as 16.0549999999999997 and the built-in is the more accurate of the two for 64-bit floats, though slower.

The reason is how NumPy rounds to positive decimals. The manual describes it as equivalent to np.true_divide(np.rint(a * 10**decimals), 10**decimals): scale up, round to the nearest integer, scale back. That scaling step can introduce error. The manual’s example is np.round(56294995342131.5, 3), which gives 56294995342131.51, while np.format_float_positional(56294995342131.5, precision=3) gives '56294995342131.5'. Python’s own documentation makes the related point that round(2.675, 2) gives 2.67 instead of 2.68, and that this is not a bug but a consequence of most decimal fractions not being exactly representable as floats.

For research reporting this has one consequence: a rounded value is a display value. If a printed number must match a decimal string exactly, format the string rather than relying on a rounded float.

Troubleshooting

AttributeError: module ‘numpy’ has no attribute ’round_’

The NumPy 2.0 release notes list np.round_ among the removed names: “np.round_ has been removed. Use np.round instead.” Many older tutorials and scripts still call np.round_ and fail on NumPy 2.x. Replace it with np.round, which takes the same arguments.

2.5 became 2.0 and 3.5 became 4.0

This is the half-to-even rule described above, not a bug.

A rounded value is off in the last digit

See the scale-then-round explanation above. Use np.format_float_positional for display, or the built-in round for single 64-bit floats.

Integers did not change

For integer arrays a positive decimals has nothing to round. Use a negative value to round to tens, hundreds and so on.

Free alternatives

Function What it is
numpy.around Alias of numpy.round
ndarray.round Method form: a.round(decimals=0, out=None)
Built-in round(number, ndigits=None) Python standard library; ties go to the even choice; returns an int if ndigits is omitted
numpy.format_float_positional Produces a formatted string with a given precision, for display rather than computation

Other array operations that commonly sit next to rounding in an analysis are clipping values to bounds, taking logarithms and generating evenly spaced values.

FAQ

Does np.round round half up?

No. Exactly halfway values go to the nearest even value, so 0.5 and 2.5 round to 0.0 and 2.0.

What is the difference between np.round and np.around?

None in behaviour: numpy.around is an alias of numpy.round.

How do I round to the nearest ten or hundred?

Pass a negative decimals. With decimals=-1, 11 becomes 10.

Why does np.round_ fail?

It was removed in NumPy 2.0. Use np.round.

Does np.round change my original array?

No. It returns a new array unless you pass out.

Sources

Checked against the official documentation on 2026-10-29.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about NumPy Round: np.round Syntax, Decimals and Half-to-Even

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →