Method and source check
Last checked:
Automated source and implementation review, including worked examples and documented numerical limits. This review does not provide professional advice or specialist approval.
Method
Divide the entered percentage by 100. Parse the accepted number’s decimal string into integer digits and exponent, then simplify the equivalent fraction with BigInt GCD.
decimal = percent / 100
fraction = simplified percent / 100
Variables and units
- percent
- entered percentage, unitless
- decimal
- ratio equivalent, unitless
Worked example
12.5% = 0.125 = 1/8.
Limitations
Decimal output uses JavaScript number precision. The fraction is simplified exactly from the accepted number’s decimal string, including exponent notation.
- Input is a JavaScript number, so values beyond its representable precision may already be rounded before conversion.
- A nonzero percentage whose division by 100 underflows to zero is rejected; no equality to zero is presented for that input.
- 25% → 0.25 and 1/4
- 12.5% → 0.125 and 1/8
- 0.0000001% → 1e-9 and 1/1000000000
- 5e-324% is rejected with a percentage-field range error rather than claiming a zero decimal is equal to a nonzero fraction.