Hi,
I have to compare decimal values from a field with fraction values from another field. Basically, the values in both fields are same i.e, a '6.75' value in the decimal field is '6 3/4' in the code field which I want to compare to trigger another set of codes if they match. For this, I have to convert the decimal value to fraction. Is there a way to do this ?
I searched quite a bit to find a related topic but couldn't seem to find any.
Thanks a lot for your help.
Thanks & Best Regards,
Ram.
0
Comments
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
As examples, the fraction .75 can be expressed as 75/100 or .abcd can be expressed as abcd/10000, etc.
Then it's just a matter of reducing the fraction to the smalles whole denominator. I would assume that the easiest is to keep on dividing with the smallest prime number (2) until you cannot do that anymore, then go to the next (3) and do the same, etc.
So for example:
75/100 = 15/20 (divide by 5, as neither 2 or 3 can be used)
=3/4 (second iteration with 5). And since (5>3) or (5>4) = true, then you're done.
Microsoft - Dynamics NAV
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Thank you for this, Rashed. Maybe this sentence describes a difference between the POV of a consultant (paid by the customer) and a product developer at Microsoft. Yes, we want to get paid. And yes, this has become increasingly difficult with the newer releases of NAV. But at least IMO, our abilities haven't faltered.
With best regards
Jens
And yes, I know someone has to pay - I used to work as a consultant and had to bill my time, and no, my customers wouldn't think it was "fun" to pay for new development.
Microsoft - Dynamics NAV
Don't take it personal and please keep on posting here. I found your solution interesting to read.
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
Also +1. Never mind the frustration, we also do things for fun... and profit.
With best regards
Jens
Rashed, I did as you said last saturday.
I split the fraction into individual integers, converted into decimals and added it to the while number.
But, I guess we can not do in Navision what I had originally asked...
Thanks again.
Ram.
The Euclidean algorithm provides a nice method of finding the greatest common divisor (GCD) of two positive integers. The GCD of the numerator and denominator of the fraction can be used to reduce the fraction to lowest terms.
That would be the ideal solution. But it is difficult to implement in Navision in the absence of any readily available function. For eg. at the first step itself, we have to separate the whole number and the decimal parts, then find the number of decimals and divide by 100, 1000 or so on accordingly. The next challenge is to make the system recognize and divide the numerator and denominator only by prime numbers starting with the least until you reach a point where you cannot divide any further.
Such a function, if attempted, would take time to develop but I think would definitely be worthwhile.
Maybe Microsoft can consider for future versions.
Ram.