# How to calculate the Integer portion of a fraction using only +, -, $\div$ and *?

I made something in excel that calculates the days left until a given date, and from that how many weeks were left. I had it so that 9 days displayed as 1.2 using this formula: $$\frac{\left(\frac{A}{B}-\Bigl\lfloor{\frac{A}{B}}\Bigr\rfloor\right)\cdot B}{10}+\Bigl\lfloor{\frac{A}{B}}\Bigr\rfloor$$

Where $B$ is the "base" you are counting in and $A$ is the number you are trying to count.

This all works and the question is purely for personal interest only.

So, Is there a way to calculate the Integer portion of a fraction only using the operators +, -, $\div$ and *? Thanks In Advance

• Please use LaTex!!! Commented Mar 23, 2015 at 11:45
• Two other functions come to mind that have roughly the same effect: CEILING and TRUNCATE. All three are doing an "integer modulus" operation, which in another programming environment might be accomplished by casting to an int. Mathematically, these three functions are the main way to get at this information, as there isn't much else that distinguishes one side of the decimal point from the other. Commented Mar 23, 2015 at 11:50
• Sorry @BarakManos was trying to figure out how to use it, so I thought I'd post the question and then change it :) Commented Mar 23, 2015 at 12:06
• @abiessu , I know the functions that work with decimals and integers, I'm more wondering how to do it without using these functions. Commented Mar 23, 2015 at 12:06
• The answer to the question in the title is $\Bigl\lfloor{\frac{A}{B}}\Bigr\rfloor=\frac{A-A\bmod{B}}{B}$. The question in the body I do not understand, perhaps you can think of a way to clarify it. Commented Mar 23, 2015 at 12:18

$$\left \lfloor{\frac{A}{B}}\right \rfloor = \left\{\begin{array}{lr} \frac{|A| - |A| \% |B|}{|B|} , & \text{for sgn(A) } = \text{sgn(B)} \\ -\frac{|A| - |A| \% |B|}{|B|} - 1, & \text{for sgn(A) } \neq \text{sgn(B)} \end{array} \right\}$$