Group Admins

  • Profile picture of Karim
  • Profile picture of Jean

OpenMusic

Public Group active 20 hours, 9 minutes ago

User group for OpenMusic and computer-aided composition. Visit the Forum for discussions.

Fraction to Decimal

Author 2 Subscribed Users |
Profile photo of nagymusic
nagymusic

Hello!
Is there a function that translates a list of fractions into a list of decimals (1/4 to 0.25) and vice versa? I know that one could construct a patch for this, but I thought it might be worth asking just in case.

Thank you!

March 28, 2018 at 02:41 #26046
Profile photo of Karim
Karim

Hi,

Certainly for the first question. Just use the float function.
Concerning the other one you can do for simple floats (not irrationals) – see screenshot
if you have for example pi (3.1415…) or 1/3 = 0.33333…. these will not render exactly as a ratio but will be approximated.

Best
K

Attachments:
  1. Screenshot_2018-03-28_04-06-11

    Screenshot_2018-03-28_04-06-11.png

  2. Screenshot_2018-03-28_04-06-11

    Screenshot_2018-03-28_04-06-11.png

March 28, 2018 at 03:19 #26047
Profile photo of nagymusic
nagymusic

Thanks, Karim. I had a chance to experiment with your suggestions (see the patch attached). The conversion from fractions to decimals works great (1/4 1/8 = 0.25 0.125). While the opposite produces the desired outcome, it’s still not computing the same values (0.25 0.125 = 1/4 3/25). My goal is to be able to go back and forth by keeping the same values, e.g, 0.25 0.125 = 1/4 1/8.

I welcome your thoughts. Thank you once again!

March 28, 2018 at 17:47 #26065
Profile photo of Karim
Karim

Oh sorry
should have explained more. 0.125 have 3 decimals so instead of 100 you should use 1000
and you will get 1/8
If the decimals are finite and not endless (like dividing by 3 or 7 etc…) you just have to calculate the number of decimals and multiply by 10

Best
K

March 28, 2018 at 19:21 #26068
Profile photo of nagymusic
nagymusic

Thanks! This is great.

March 30, 2018 at 16:57 #26084

You must be logged in to reply to this topic.

Log in now