FIRSTDIGIT - extract the first digit from a numeric field

1 post / 0 new
Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57
FIRSTDIGIT - extract the first digit from a numeric field

This custom function comes out of a scripting course I give in which we create a script that performs benford 1st digit analysis at the client or vendor level instead of over the entire database.  One of the steps is to extract the first digit of the numeric field that we are looking at.  So usually we create the forumal using the equation editor but I thought it would be fun to create a custom function to do the same thing.  So here it is, it should be easy to modify for more than 1 digit.  It will extract the first digit, it ignores the negative sign and if the number is a decimal it will ignore the decimal and use the first non 0 number as the first digit.