Yup, I looked up a 30 years old Smalltalk implementation. The translation was pretty straight forward but I was not able to extend the Python Number class (as natural in Smalltalk).
def intlPrintRoundedMax(aNumber, decs, insigDecBool, thousBool, lZeroBool, positiveSignBool) :
"""Answer a string, the ASCII representation of the receiver rounded to decs decimal
places using delimiters from locale.
If <insigDecBool> is false only append significant decimals.
If <thousBool> is true, insert delimiter for thousands.
If <lZeroBool> is true, a leading zero is printed.
If <positiveSignBool> add sign to positive numbers"""
"""920416 TA c"""
locales = locale.localeconv()
sDecimal = locales['decimal_point']
sThousand = locales['thousands_sep']
sPositiveSign = locales['positive_sign'] if positiveSignBool else ''
sNegativeSign = locales['negative_sign']
answer = ''
rounder = 10 ** decs
value = round(aNumber * rounder)
if (value < 0) :
answer += sNegativeSign
value = 0 - value
else :
if (value != 0) : answer += sPositiveSign
if (lZeroBool) :
divisor = 10 * rounder
else :
if (value == 0) :
answer += '0'
return answer
divisor = rounder
while (divisor <= value) :
divisor = divisor * 10
if (thousBool) :
thousands = thousandRounders = 1000 * rounder
while (thousands <= value) :
thousands = thousands * 1000
thousands = max((thousands // 1000), thousandRounders)
else : thousands = None
if (divisor == rounder) : answer += sDecimal
divisor = divisor // 10
while (divisor > 1) :
answer += chr(value // divisor + 48)
value = value % divisor
if ((not insigDecBool) and ((value == 0) and (divisor <= rounder))) :
return answer
if (divisor == thousands) :
thousands = max((thousands // 1000), thousandRounders)
answer += sThousand
if (divisor == rounder) : answer += sDecimal
divisor = divisor // 10
answer += chr(value + 48)
return answer