I am pretty sure the IDL's numeric string formatting commands do not allow a user to move the position of the decimal point from its position as the second non-blank character in the output string. Thus, one would have to create their own parser of IDL scientific format to decompose the IDL-formatted string, modify its subelements, and reassemble it in the format you desire. Below is a function with one algorithm that I think would work. It takes any real number as an argument and returns the format you are looking for: decimal-free coefficient and exponent with no leading zeroes.
; Call this with syntax:
; myNumberString = ELIMINATE_DOT_IN_SCIENTIFIC_FORMAT(myNumber)
FUNCTION eliminate_dot_in_scientific_format, number
; Convert number to a scientifically formatted string
sciFormattedString = string(number, FORMAT='(e0)')
; Split the scientific format string into three substrings,
; separated at the dot and the 'E' or 'e'
splitString = strsplit(sciFormattedString, '[.e]', /REGEX, /EXTRACT)
; Get rid of excess 0's in the second element of 'splitString'. To do
; this we flip all the digits, let IDL's LONG() function parse out the
; unnecessary zeroes (which are leading zeroes after the flip), then
; flip the digits in the integer back to their original sequence.
; This requires multiple intermediate STRING() and BYTE() conversions.
temp = string(reverse(byte(string( $
long(string(reverse(byte(splitString[1])))), FORMAT='(I0)'))))
splitString[1] = temp
; Calculate how much the exponent value has to be incremented
exponentSubtractor = strlen(splitString[1])
exponentMagnitude = fix(splitString[2])
exponentMagnitude -= exponentSubtractor ; decrement the value
; Make this into a string using the sign character of the third element
newExponentString = string(exponentMagnitude, FORMAT='(I+0)')
reformattedString = splitString[0] + splitString[1] + 'e' + newExponentString
return, reformattedString
END
James Jones
|