In all cases in this State when a sentence has been imposed by any judge, magistrate, mayor or intendant of any city or town in the alternative, by fine or imprisonment, and the person upon whom the sentence has been imposed shall enter upon the service of the sentence and thereafter such person or anyone in his behalf shall desire or offer to pay the fine imposed by the sentence, the clerk of the court in the county in which the sentence was imposed or the judge, magistrate, mayor or intendant who imposed the sentence shall apportion the fine imposed therein, so that the person or anyone in his behalf shall be allowed to pay such part of the fine as shall be in proportion to the balance of the time to be served under the sentence. Upon the payment of such proportionate part of the fine, the clerk, judge, magistrate, mayor or intendant shall release and discharge the person in behalf of whom the fine is so paid from further custody.