Sep 01, 2009 21:49
I find people like to change data types, go from concrete to abstract and back to concrete, and overall come up with solutions that no longer match the problem(s).
So while arguing a point recently, I provided a simple solutions as an alternative, but my solution had a flaw that I intended to be discovered. It wasn't, but likely because the person felt the "flaw" wasn't a flaw.
More specifically, I was suggesting one could do some stuff to a number, then "round" the number. I was hoping the person would attack my suggestion of "rounding" a number since that is a very abstract concept.
So...rounding. Here's your challenge. Given an unknown number, provide a function for "rounding" that number. In your function, the number has to remain exactly the same data type - this limitation is really the general point to the novel solution in the first place. By "data type" it is important to note that if you take a number like "4.6" and evaluate the number by saying something like "is the number to the right of the decimal greater than 5?" then you are no longer treating the number like a number - you're treating it like a string of characters. The characters could just as easily be "cars.trucks" and then you're evaluating "trucks" to round up to the nearest cars...get the point?
A number is a number. It is a concrete value of some precision - one which is hopefully precise enough to be of use. Converting it to a string, or some abstract concept, is both disingenuous and pointless. You're taking something that is overwhelmingly simple (a number) and doing silly, pointless things to it.
So - how would you round a decimal number, in a formula that maintains the number's data type integrity? Can you come up with a simple solution?