Let us say you have the number 1234. If we were to "remove" the number 3, we would have 124. I have seen this operation in many programming tutorials, but I do not know what mathematical operation, if any, this maps onto. What is the mathematical term for this option, and how is it written?
Asked
Active
Viewed 401 times
0
1 Answers
2
To remove the $10^d$'s digit from $x$, you can take $x - 10^d (\lfloor x/10^d \rfloor - \lfloor x/10^{d+1} \rfloor)$.
Thus in your example with $x=1234$ and $d=1$, $1234 - 10 (\lfloor 123.4 \rfloor - \lfloor 12.34 \rfloor) = 124$.
Robert Israel
- 448,999
- (n% 10)$ where $%$ is the usual computer science meaning of mod (which can also be rewritten in terms of floor functions if one prefers)
– JMoravitz Jun 12 '20 at 14:090.1+0.2 != 0.3). Unless if you are doing billions of these operations you shouldn't notice a difference. Having the code be readable and understandable is often more useful than unnoticeable improvements in performance. – JMoravitz Jun 12 '20 at 14:14