Hello! How to obtain the amount of digits filled in a NUMERIC field? My necessity is to check if a numeric variable defined with size 17 is fully filled (contain 17 numbers, not less than this).
I’ve already tried 2 things:
Using MASK, but it doesn’t check for the quantity of digits filled
1 #NUM (N17) INIT <12345>
*
IF #NUM EQ MASK(NNNNNNNNNNNNNNNNN)
WRITE 'Field has 17 positions.'
END-IF
Using EXAMINE GIVING LENGTH, which returns only the total size (17)
If Natural delivered a LOG10 calculation it would be simpler. For this explanation, I will use LOG for LOG10 and LN for LOGe.
LOG(n) answers the question, “what power of 10 is equal to n?” For example, LOG(100) = 2, 10^2 = 100. LOG(1000) = 3, LOG(10000) = 4, etc. You’ll notice that the log is always 1 less than the count of digits in the number.
Natural’s function is really LN(n), which answers the, “what power of e, where e=2.71828…, is equal to n?” There is a simple formula to get from LN(n) to LOG(n). LOG(n) = LN(n) / LN(10).
That probably doesn’t make it any clearer, but I’m 30+ years out from my math degree and I’m afraid I can’t explain it myself.
The calculation in Natural might be better without the hard-coded magic number:
HI Jerome,
Well, according to your “math” LOG(10) is 1 (absolutely true, by the way :-); so, what’s the point to do LOG(N) / LOG(10)?
When you divide by 1, you don’t make any changes to your result, right? Puzzled
Thank you, Jerome; well, I thought there were REALLY (and why not?) LOG (X) and LN (Y); I assume the next release of Natural will include LN as well as LOG