Author Topic: change a real to a list  (Read 294 times)

0 Members and 1 Guest are viewing this topic.

Jeremy Dunn

  • Newt
  • Posts: 31
change a real to a list
« on: April 29, 2021, 04:08:20 PM »
I want to take a number and change it into a format where I have  a list of a list of digits and the exponent. Let us start with an integer first. Say we have the integer 189. We change this to scientific notation and it becomes 1.89e2 . But we actually want to shift this one place further over so we have all of the significant digits on one side. Now we have 0.189e3 . I then want this in the form ((1 8 9) 3). If the number is negative then the digits are negative so that -189 is ((-1 -8 -9) 3). If the integer is real as in 189.0 we need to be able to detect this case and chop off the trailing zeros. I wish my routine to detect general real numbers like 12.382e-3 and convert it to 0.12382e-1 and thence to ((1 2 3 8 2) -1). I was trying to do all this by turning the number into a string and then splitting it up but there must be a purely numerical way of doing this. I'm sure our local experts will have different ways of going about it. Note: 0 would just default to ((0) 1). The digit list otherwise begins with the first non-zero digit.

BIGAL

  • Swamp Rat
  • Posts: 816
  • 30 + years of using Autocad
Re: change a real to a list
« Reply #1 on: April 29, 2021, 07:44:16 PM »
Can you explain why your wanting to do this there may be better ways of a solution.
A man who never made a mistake never made anything