Fraction to Recurring Decimal
Explore how to convert a fraction given by numerator and denominator into its string representation. Learn to detect and enclose repeating decimal parts using hash maps. This lesson helps you implement the logic to handle fractional parts accurately under various constraints.
We'll cover the following...
Statement
Given the two integer values of a fraction, numerator and denominator, implement a function that returns the fraction in string format. If the fractional part repeats, enclose the repeating part in parentheses.
Constraints:
denominator-
numerator,denominator
Examples
Understand the problem
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Fraction to Recurring Decimal
Select the correct answer for the fraction given below:
20/4
“2”
“3”
“4”
“5”
Figure it out!
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself
Implement your solution in the following coding playground.
export function fractionToDecimal(numerator, denominator){// Replace this placeholder return statement with your codereturn "";}export {fractionToDecimal};