Simplify fractions

You don't have to use a translator - feel comfortable to post in your own language. Some translators are not accurate, which complicate things. We use the Yandex Translate in our community, which might be more accurate.

Also, saying that you don't have time is not an excuse for not learning App Inventor. Without learning the basics of App Inventor, how are you going to build a successful app?

A journey of a thousand miles begins with a single step. - Lao-tzu, Chinese philosopher

From @Taifun

Learning things all take time. Instead of thinking the product, think about how to make the product.

3 Likes

To turn a decimal number into a numerator and denominator,

  • split the number at '.'
    • if the resulting list has only 1 item,
      • then the numerator is item 1 and the denominator is 1.
      • else
        • set local power = 10 ^ (text length of item 2)
        • numerator = original number * power
        • denominator = power

Example with 3.14 as original number
Split at '.' to get list [3,14]
Length ('14') = 2
power = 10 ^ 2 = 100
numerator = 3.14 * 100 = 314
denominator = 100

1 Like

Yes you're right, but this is what I get.

image

Usually you might want to get a whole number as a decimal result, but that's ok.

Also, the fraction can be simplified. In the screenshot below, the top result is with built-in blocks, the next one is the extension.

image

1 Like

That's an interesting counterexample (math block 0.124354)

I think it failed in my code because of the inexact nature of AI2 floating point numbers.
split at decimal fail

Thanks, that was fun.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.