0 votes
Suppose I am having 8.8333333333333339 and I want to convert it to 8.84, how can I accomplish this in python? round(8.8333333333333339, 2) gives 8.83 and not 8.84. I am new to python or programming in general.

I don't want to print it as a string, the result will be further used.
Oct 8, 2018 in Python 2,191 views

## 1 answer to this question.

0 votes

This is normal (and has nothing to do with Python) because 8.83 cannot be represented exactly as a binary float, just as 1/3 cannot be represented exactly in decimal (0.333333... ad infinitum).

If you want to ensure absolute precision, you need the decimal module:

```>>> import decimal
>>> a = decimal.Decimal("8.833333333339")
>>> print(round(a,2))
8.83```
answered Oct 8, 2018 by
• 7,720 points

0 votes
1 answer

## How to check if a float value(decimal number) is between range(0 to 10) in python

Hello,  A function that returns True for an integer number (int or ...READ MORE

0 votes
2 answers

## How to calculate square root of a number in python?

calculate square root in python >>> import math ...READ MORE

0 votes
1 answer

## Convert floating point number to a certain precision

With Python < 3 (e.g. 2.6 [see ...READ MORE

–1 vote
2 answers

## How to filter out any digit that contains odd number in a range of number in Python?

n = list(range(10)) b = list(filter(lambda i:i%2!=0,n)) print(b) READ MORE

0 votes
1 answer

## how do i change string to a list?

suppose you have a string with a ...READ MORE

0 votes
2 answers

## how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote
2 answers

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

0 votes
1 answer

## how do i use the enumerate function inside a list?

Enumerate() method adds a counter to an ...READ MORE

0 votes
1 answer

## How to Print a List in Python

ou are using Python 2.x syntax with ...READ MORE

0 votes
1 answer

## How to correctly return an a dictionary as an output in zappier code using python?

David here, from the Zapier Platform team. ...READ MORE