Fit number into range

JNameNotTaken

New member
Joined
Oct 22, 2014
Messages
4
...well, kindof....

All help and pointers appreciated. I'm hopeless at Math in general.

The problem:
800 -> 1000
125 -> 1000


80 -> 100
43 -> 100


8 -> 10
9 -> 10


0.8 -> 1
0.23 -> 1

.08 -> 0.1

(consider -> to be "goes-to" or "rounds-up-to")

Where the number on the left is the input to some equation (presumably) and the number on the right is the output.

The numbers on the left are arbitrary, basically, I'd like to be able to throw any number at the equation and output a rounded-up-number. Rounded up to the nearest factor-of-ten according to the pattern above.

If any of that doesn't make since, I'm happy to clarify.

Thanks so much
John
 
...basically, I'd like to be able to throw any number at the equation and output a rounded-up-number. Rounded up to the nearest factor-of-ten according to the pattern above.
Please provide the full and exact text of this homework exercise, the complete instructions, and a clear statement of your efforts so far.

When you reply, kindly please clarify how this exercise, which appears to be some sort of computer-programming assignment for the work-place, arose in a grammar-school "Arithmetic" class. Thank you! ;)
 
Take the log base 10.

Thanks for the tip Ishuda.

I managed to find the solution, here's the equation:
10^(ceil(log10(x))) courtesy of here: http://stackoverflow.com/questions/19870067/round-up-to-nearest-factor-of-10

I'm not sure how the ceil part can be represented outside a programming context but in essence it's just a round-up-to-nearest-integer.
Here's a worked example for anyone who stumbles across this in the same boat:
http://jsfiddle.net/jralston/rjuL5o8v/

http://outbottle.com/rounding-a-number-up-to-its-nearest-factor-of-ten/ Homework?
 
Top