## Rounding two values together to a "fancy" value

Problem Description:

I have a total price T and a customer total price C. I have an amount A. I have a single piece price S.

Let us say, my total price T is 11. The amount, how much items a package includes, is 6. So for 11, I get a package of 6. The single pice price S would be T/A, 11/6 = 1,83333. 1,833333 is not a fancy value. Here, I want to set the S manually to 1,84.

C is the total price I give to customers. So C is the fancy value of T.

Well, with S=1,84 I get a C of SxA=1,84×6=11,04. 11,04 is again an ugly value. Here, I want to set C to 11,10. So S would be 1,85 now.

In formula: C/A=S ……. where C should be rounded to 0,1 decimals and S to 0,01 decimals in parallel.

Is there a way to create a formula to calculate my C and S based on the input T and A ?

## Solution – 1

I’ll use Python

```
from math import ceil
# 'round' is available in Python's default workspace.
# 'ceil' and 'floor' must be imported from the math library.
# Try each of those, to see which one you want.
#
# From the question, I assume you want 'ceil'.
T = 11
A = 6
S_fancy = ceil(T/A*100)/100
print('S_fancy =', S_fancy)
C_fancy = ceil(S_fancy*A*10)/10
print('C_fancy =', C_fancy)
S_even_fancier = ceil(C_fancy/A*100)/100
print('S_even_fancier =', S_even_fancier)
```

Running that, you’ll get:

```
S_fancy = 1.84
C_fancy = 11.1
S_even_fancier = 1.85
```

I hope this helps. Again, try among these: `round`

, `ceil`

, and `floor`

.