I have encoutered a problem in a software that I use for invoicing. I have a variable (quantity) integer A which I want to split in a sum of two integers using a percentage p where $A1 = p*A$ and $A2 = (1-p)*A$.
Currently the software is using a rounding function. But as it takes a percentage of the value and rounds it to two integers, the equation (very often) is no longer true. This is the sum of A1 and A2 is not A.
More formally: Let A be a positive integer ($A \in Z^+$) and $p \in [0,1]$. I want $A = A1+A2$ where $A1, A2 \in Z^+$
I came up with this
$$A = \lfloor{p*A\rfloor} + \lceil{(1-p)*A\rceil}$$
where I make use of the floor and ceil function. Does it make sense, is this true?