Splitting Numbers into component parts
Posted: Mon May 02, 2005 11:17 pm
I would like to write a function NumberParts that takes an integer or real and returns it as a list with the list of digits composing the number in a list along with the exponent i.e. the number of places that one must move the decimal point left or right. Some examples:
123 -> ((1 2 3) 3)
-12 -> ((-1 -2) 2)
0.12 -> ((1 2) 0)
0.00045 -> ((4 5) -3)
One notes that negative numbers have negative digits in the digit list. My question is what is the best way to do this to get the full precision of both integers and reals? It is trivial to convert such a list into a number but I am not certain of the best way to do the reverse. Any suggestions?
123 -> ((1 2 3) 3)
-12 -> ((-1 -2) 2)
0.12 -> ((1 2) 0)
0.00045 -> ((4 5) -3)
One notes that negative numbers have negative digits in the digit list. My question is what is the best way to do this to get the full precision of both integers and reals? It is trivial to convert such a list into a number but I am not certain of the best way to do the reverse. Any suggestions?