;+
; NAME:
; leading_digit
;
;
; PURPOSE:
; return the leading digit of a number. E.g. 1234 -> 1, 0.345 -> 3.
; This is used in the computation of Benford's Law
; (http://en.wikipedia.org/wiki/Benford%27s_law)
;
;
; INPUTS:
; in: number (or array of numbers) to find the leading digit of
;
;
; OUTPUTS:
; the leading digit of the number
;
;
; EXAMPLE:
; IDL> print, leading_digit([0.0034, 6123, 0, -0.12343])
; 3 6 0 1
;
;
; MODIFICATION HISTORY:
;
; Mon Jun 16 16:36:17 2008, Brian Larsen
;
; written and tested
;
;-
FUNCTION leading_digit, in
compile_opt strictarr
in2 = trim(string(abs(in), format = '(e)'))
ans = strmid(in2,0, 1)
RETURN, ans
END