Please note: This wiki is currently running in test mode after an attack on January 5 2013. All passwords were reset, so you will have to use the password recovery function to get a new password. To edit wiki pages, please log in first. See the wiki attack description page for more details. If you find problems, please report them to the pydotorg-www mailing list.

# Asking for Help: How can I add or substract two to the last digit of a float?

How can I add or substract two to the last digit of a float? Like 4.9999 should be 5.0001 or 4.9997. The problem is

```>>> 4.9999
4.9999000000000002
would yield 4.9999000000000000 or 4.9999000000000004 which is not right.
I could make a str(4.9999), convert each character to an int and work on each character from right
to left, but there must be a better way.
this is not what I want as well:
>>> ( 4.9999 * 10000 + 2 ) / 10000.0
5.0000999999999998 -> this should be 5.0001
this makes it somehow :))
>>> str(( 4.9999 * 10000 + 2 ) / 10000)
'5.0001'```

Asking for Help/How can I add or substract two to the last digit of a float? (last edited 2009-11-07 01:11:44 by PaulBoddie)