Options

Convert decimal value to fraction

ramsay18477ramsay18477 Member Posts: 52
edited 2013-09-14 in NAV Three Tier
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.

Comments

  • Options
    ara3nara3n Member Posts: 9,255
    change the fraction to decimal instead
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    BardurKnudsenBardurKnudsen Member, Microsoft Employee Posts: 137
    ..but the other way is more fun for a developer :-)
    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.
    Bardur Knudsen
    Microsoft - Dynamics NAV
  • Options
    ara3nara3n Member Posts: 9,255
    It's not fun when it's on customer 's time.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    jglathejglathe Member Posts: 639
    ara3n wrote:
    It's not fun when it's on customer 's time.

    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
  • Options
    BardurKnudsenBardurKnudsen Member, Microsoft Employee Posts: 137
    My opologies for an insensitive comment. I just meant that sometimes we as developers welcome uncommon problems.
    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.
    Bardur Knudsen
    Microsoft - Dynamics NAV
  • Options
    mdPartnerNLmdPartnerNL Member Posts: 802
    Working with Microsoft has some pro's but this one of the con's. :D

    Don't take it personal and please keep on posting here. I found your solution interesting to read.
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    Don't take it personal and please keep on posting here. I found your solution interesting to read.
    +1
  • Options
    jglathejglathe Member Posts: 639
    Don't take it personal and please keep on posting here. I found your solution interesting to read.

    Also +1. Never mind the frustration, we also do things for fun... and profit. :)

    With best regards

    Jens
  • Options
    ramsay18477ramsay18477 Member Posts: 52
    Thanks a lot everyone.

    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.
    Thanks & Best Regards,

    Ram.
  • Options
    jreynoldsjreynolds Member Posts: 175
    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.

    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.
  • Options
    ramsay18477ramsay18477 Member Posts: 52
    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. :)
    Thanks & Best Regards,

    Ram.
Sign In or Register to comment.