Discuss Scratch

Iloas000
Scratcher
10 posts

Repeated Decimal to Fraction

Hi! Is there a way to convert a repeated decimal to a fraction? Thank you.
awesome-llama
Scratcher
1000+ posts

Repeated Decimal to Fraction

What is the scenario this is needed?
Rival8347U
Scratcher
100+ posts

Repeated Decimal to Fraction

Yeah?
Iloas000
Scratcher
10 posts

Repeated Decimal to Fraction

Just a calculator.
PutneyCat
Scratcher
500+ posts

Repeated Decimal to Fraction

Google will give you the answer right away. The basic idea is to do a subtraction that eliminates the repeating digits.

Simple example with x = 0.3333333333….(repeating)
multiply by 10
10x = 3.333333333…(repeating)
subtract x from 10x (meaning you lose all the repeating digits after the decimal point)
9x = 3
divide by 9
x = 3/9
simplify fraction
x = 1/3
Iloas000
Scratcher
10 posts

Repeated Decimal to Fraction

Is there a code to find the repeated part of a decimal?
Cool_Coder_1587
Scratcher
100+ posts

Repeated Decimal to Fraction

This code doesn't simplify the fraction, but it still works. “result” is the variable containing the fraction. I have literally no idea how this works, so please let me know if there are any issues with it.

define convert (num) to fraction // Remember to check the "run without screen refresh" box!
set [denominator v] to ((1)/(num)
set [result v] to (join [1/](denominator)
if <(num) > (1)> then{
set [result v] to (join (num) [/1]
if <(num) contains [.]?> then
set [i2 v] to [0
repeat until <not <(result) contains [.]>?
change [i2 v] by [1]
set [result v] to (join ((num) * (i2))(join[/](i2)
}else{
if <(denominator) contains [.]?> then
set [result v] to (join (num)[/1]
delete all of [find dot v]
set [i v] to [0]
repeat (length of(num)
change [i v] by [1]
add (letter (i) of (num)) to [find dot v]
end
set [char v] to []
set [i v] to [0]
repeat until <(char)=[.]>
change [i v] by [1]
set [char v] to (item (i) of [find dot v]
end
repeat (i)
delete [1] of [find dot v]
end
set [result v] to (join ((find dot) + ()) (join [/]([10^ v] of (length of [find dot v]):: operators
}::control

Powered by DjangoBB