Algorithm to transform fraction from decimal to specified system