JenniferMurphy
Well-known Member
- Joined
- Jul 23, 2011
- Messages
- 2,531
- Office Version
- 365
- Platform
- Windows
This is probably obvious, but not to me.
I am trying to write a little UDF to convert a probability (0-1) into a fraction (ratio). For example, 25% would become "3/1", 40% would become "1.5/1", etc.
I have that working. Now I want to convert any fractions that are not integers in the numerator to another fraction that is. For example. 40% would become "3/2" instead of "1.5/1". To my addled brain, the code below should work. It even looks like it is working, but it is not. What I am doing is multiplying that numerator (1.5) by the integers from 1 to 10. If any of those results are an integer, I return that value with the multiplier (denom) as the denominator.
In the example below, the UDF is passed "0.4". It converts that to "1.5" (frac). On the second pass through the For loop (denom = 2), the numerator (numer) appears to be "3", but it fails the test against Int(numer). In the Immedite window, numer is "3", but int(numer) is "2".
Can someone tell me what is going on?
I am trying to write a little UDF to convert a probability (0-1) into a fraction (ratio). For example, 25% would become "3/1", 40% would become "1.5/1", etc.
I have that working. Now I want to convert any fractions that are not integers in the numerator to another fraction that is. For example. 40% would become "3/2" instead of "1.5/1". To my addled brain, the code below should work. It even looks like it is working, but it is not. What I am doing is multiplying that numerator (1.5) by the integers from 1 to 10. If any of those results are an integer, I return that value with the multiplier (denom) as the denominator.
In the example below, the UDF is passed "0.4". It converts that to "1.5" (frac). On the second pass through the For loop (denom = 2), the numerator (numer) appears to be "3", but it fails the test against Int(numer). In the Immedite window, numer is "3", but int(numer) is "2".
Can someone tell me what is going on?