StockFetcher Forums · Filter Exchange · How to extract specific digits from values << >>Post Follow-up
485 posts
msg #105079
2/21/2012 3:35:58 AM

For example: I want the hundredth digit of the close of SPY on 2/17/2012 = 136.41

This method worked as expected:
a) 136.41 * 100 = 13641.33 ... shift hundredth digit 2 places to left, revealing additional precision
b) mod(13641.33,1) = remainder of (13641.33/1) = 0.33 ... frac() and int() functions would also be useful for these
c) 13641.33 - 0.33 = 13641.00 ... clean up the right side
d) 13641.00 / 10 = 1364.10 ... shift digits 1 place to right
e) mod(1364.10,1) = remainder of (1364.10/1) = 0.10
f) 0.10 x 10 = 1.00 ... shift digit 1 place to left

Fetcher[
/* ===== extract hundredth digit ... with NO rounding of the hundredth digit ===== */
set{a, close * 100}
set{b, mod(a, 1)}
set{c, a - b}
set{d, c / 10}
set{e, mod(d,1)}
set{f, e * 10}

]

*Here is another version that I thought would work, but for some reason this method did not produce the results I expected. In some cases it rounded the hundredth digit up and in other cases it rounded the hundredth digit down.
a) 136.41 * 10 = 1364.133
b) mod(1364.133,1) = remainder of (1364.133/1) = 0.133
c) 0.133 x 10 = 1.33
d) mod(1.33,1) = 0.33
e) 1.33 - 0.33 = 1.00

Fetcher[
/* ===== extract hundredth digit from close ... with rounding of the hundredth digit ===== */
set{a, close * 10}
set{b, mod(a, 1)}
set{c, b * 10}
set{d, mod(c, 1)}
set{e, c - d}

]

 guru_trader485 postsmsg #105110- Ignore guru_trader 2/22/2012 3:46:52 PMIn case you want to know if that hundredth digit is odd or even ... using this definition of an even number ... there is no remainder after dividing the number by 2 Fetcher[ /* ===== extract hundredth digit ... with NO rounding of the hundredth digit ===== */ set{a, close * 100} set{b, mod(a, 1)} set{c, a - b} set{d, c / 10} set{e, mod(d,1)} set{f, e * 10} /* ===== is hundredth digit even or odd ===== */ set{g, mod(f,2)} set{h, g - mod(g,1)} set{even, count(h equals 0,1)} set{odd, count(h greater than 0,1)} add column even add column odd ]
 StockFetcher Forums · Filter Exchange · How to extract specific digits from values << >>Post Follow-up

*** Disclaimer *** StockFetcher.com does not endorse or suggest any of the securities which are returned in any of the searches or filters. They are provided purely for informational and research purposes. StockFetcher.com does not recommend particular securities. StockFetcher.com, Vestyl Software, L.L.C. and involved content providers shall not be liable for any errors or delays in the content, or for any actions taken based on the content.