🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to NumPy Notes
Topic #35

ufunc Rounding Decimals


Rounding Decimals

There are primarily five ways of rounding off decimals in NumPy:

  • truncation
  • fix
  • rounding
  • floor
  • ceil

Truncation

Remove the decimals, and return the float number closest to zero. Use the trunc() and fix() functions.

Example

  import numpy as np

arr = np.trunc([-3.1666, 3.6667])

print(arr)

Example

  import numpy as np

arr = np.fix([-3.1666, 3.6667])

print(arr)

Rounding

The around() function increments preceding digit or decimal by 1 if >=5 else do nothing.

E.g. round off to 1 decimal point, 3.16666 is 3.2

Example

  import numpy as np

arr = np.around(3.1666, 2)

print(arr)

Floor

The floor() function rounds off decimal to nearest lower integer.

E.g. floor of 3.166 is 3.

Example

  import numpy as np

arr = np.floor([-3.1666,
  3.6667])

print(arr)

Ceil

The ceil() function rounds off decimal to nearest upper integer.

E.g. ceil of 3.166 is 4.

Example

  import numpy as np

arr = np.ceil([-3.1666,
  3.6667])

print(arr)

Want to go beyond the notes?

Join CodingNow 2.0's NumPy course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

ufunc Rounding Decimals – FAQs

Quick answers about learning ufunc Rounding Decimals in NumPy.

This free note from CodingNow 2.0 explains ufunc Rounding Decimals in NumPy — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every NumPy topic on CodingNow 2.0, including ufunc Rounding Decimals, is 100% free with no signup required.
With focused practice, most students grasp ufunc Rounding Decimals in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now