Skip to content

Converts strings representing rational numbers in decimal notation into fractions, including repeating decimals! Eg.: -4.3(7) = -4.37777777... = -197/45. [how to change rational numbers in decimal form to fraction form]

Notifications You must be signed in to change notification settings

t3m2/Converting-rational-numbers-in-decimal-notation-to-fractions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 

Repository files navigation

👉 Run on Repl.it 👈

Converting rational numbers in decimal notation to fractions

This repository contains a Python program that converts strings representing rational numbers, in decimal notation, to simplified fractions in form "n/m" where n and m are integers.

If the number is a repeating decimal, its period should be between round brackets since this is the easier way to represent it using a regular keyboard.

For example: -2,5(37) = -2,537373737373737... = -1256/495.

Input: "-2,5(37)" results in output: "-1256/495".

This is particularly useful when we have a repeating decimal and want to write it as a simplified fraction. For instance, the number 825,27(123) is equal to which simplified fraction (in form n/m where both n and m are integers)? You can use the program to find out.

This only works with rational numbers because rational numbers are all the numbers and the only numbers that can be written as the divison of two integers, that is the definition of rational numbers. Note that recurring decimals (dízimas infinitas periódica) are rational numbers, and that 0,(9)=1.

This repository consists of the following files:

Note that operation with floats are not exact so, approximations are a possibility, the program doesn't have infinite precision, and numbers that are too big or too small will be approximated or result in an error...

👋😃👍

About

Converts strings representing rational numbers in decimal notation into fractions, including repeating decimals! Eg.: -4.3(7) = -4.37777777... = -197/45. [how to change rational numbers in decimal form to fraction form]

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages