Question: Say I have a condition that if a number ends with.00 add 2 to it and if a number ends with.99 add 3 to it. So if I had 5.00 and 5.99, I want to write a nested if statement that would allow me to add the right value to the original number based on its ending.

How to do that in R (or python)?

Answer: 
Due to [floating point precision](https://stackoverflow.com/questions/588004/is-floating-point-math-broken), you will need to round your numbers to two decimals as values such as `5.99` cannot be represented exactly. This means a value such as `5.9921875` will have to fulfill your criterion as *finishing with 0.99*.

If you are fine with that, using [Python's Format Specification Mini-Language](https://docs.python.org/3/library/string.html#format-specification-mini-language) 
 will round implicitly and allow to extract the required decimals.

```
def get_decimals(num, n=2):
    return '{0:.2f}'.format(num)[-2:]

def func(num):
    decs = get_decimals(num)

    if decs == '00':
        return num + 2
    elif decs == '99':
        return num + 3
    else: return num

```
It seems there are other values in your list/vector you need to deal with. I will give a vectorized format:

in R:

```
data = c(5.00,5.99,5.61)
mm = function(x){
  x = round(x,2)
  y = x-as.integer(x)
  ifelse(round(y-0.00,2)==0, x+2,ifelse(round(y-0.99,2)==0,x+3,x))
} 

mm(data)
[1] 7.00 8.99 5.61

```

In Python: vectorized format with `numpy module`

```
import numpy as np
x = np.array([5.00,5.99,5.61])
def mm(x):
    x = np.round(x,2)
    y = x - np.array(x,dtype = 'i')
    return np.where(np.round(y-0.00,2)==0, x+2,np.where(np.round(y-0.99,2)==0,x+3,x))

mm(x)
array([7.  , 8.99, 5.61])

```