I started this as a joke among friends, telling that converting numbers to other integer bases is for n00bs, while an actual coder at least converts numbers to more complex bases like [pi (or π or however you wish to spell it in your language)](http://en.wikipedia.org/wiki/Pi), so they dared me proving I was better.

And I did it in few hours, discovering that what I started as a joke actually has [some math ground and application (particularly the conversion to base pi, it seems)](http://en.wikipedia.org/wiki/Non-integer_representation).

That said, now I am daring you to do the same, that is to build a function so that it takes a **number** (any number, you are warned!) and optionally the **number of decimals** (default: 0) and a **base** (default: pi), returning the proper conversion **as a string**:

#Note
In Java there is no easy way with optional parameters so all three parameters will be given; the same in C# because, as of now, the used version is not known. 

```python
converter(13) #returns '103'
converter(13,3) #returns '103.010'
converter(-13,0,2) #returns '-1101'
```

I know most of the world uses a comma as a [decimal mark](http://en.wikipedia.org/wiki/Decimal_mark), but as English language and culture are *de facto* the Esperanto of us coders, we will stick to our common glorious traditions and uses, adopting the trivial dot (".") as decimal separator; if the absolute value of the result is <1, you have of course to put one (and only one) leading 0 before the decimal separator.

Finally, you may assume that decimals if provided will always be >= 0 and that no test base will be smaller than 2 (because, you know, converting to base 1 is pretty lame) or greater than 36; as usual, for digits greater than 9 you can use uppercase alphabet letter, so your base of numeration is going to be: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.

That is my first 3-languages-kata, so I count on you all to give me extensive feedback, no matter how harsh it may sound, so to improve myself even further :)

Source: codewars | Difficulty: MEDIUM_HARD
Tags: Fundamentals

Mathematics

Starter code: def converter(n, decimals=0, base=pi):
	

Solutions:
from math import *
DIGS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def converter(n, decimals=0, base=pi):
	(lst, n) = (['-' * (n < 0)], abs(n))
	pMax = max(0, n and int(log(n, base)))
	for p in reversed(range(-decimals, pMax + 1)):
		if p == -1:
			lst.append('.')
		p = base ** p
		(d, n) = (n / p, n % p)
		lst.append(DIGS[int(d)])
	return ''.join(lst)


from math import pi
from math import log

def converter(n, decimals=0, base=pi):
	DIGITS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	representation = []
	if n < 0:
		representation.append('-')
		n *= -1
	if n == 0:
		decimalCount = 0
	else:
		decimalCount = int(log(n, base))
	for dplace in [pow(base, power) for power in range(decimalCount, -1 - decimals, -1)]:
		rNumber = int(n / dplace)
		n -= rNumber * dplace
		representation.append(DIGITS[rNumber])
		if dplace == 1 and decimals > 0:
			representation.append('.')
	return ''.join(representation)


from math import pi

def converter(n, decimals=0, base=pi):
	newbase = ''
	temp = base
	highdigit = 1
	if n < 0:
		newbase = '-'
		n *= -1
	while temp <= n:
		temp *= base
		highdigit += 1
	for i in reversed(list(range(-decimals, highdigit))):
		temp = int(n / base ** i)
		if temp > 9:
			digit = chr(55 + temp)
		else:
			digit = str(temp)
		newbase += digit
		n -= temp * base ** i
		if i == 0 and decimals > 0:
			newbase += '.'
	return newbase


from math import pi, log

def converter(n, decimals=0, base=pi):
	if n == 0:
		return '0' if decimals == 0 else '0.' + '0' * decimals
	lexiconums = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	res = '' if n > 0 else '-'
	n = abs(n)
	for i in range(int(log(n) / log(base)), -decimals - 1, -1):
		divisor = base ** i
		res += lexiconums[int(n / divisor)]
		if i == 0 and decimals > 0:
			res += '.'
		n %= divisor
	return res


from math import pi
import math
numbers = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def converter(n, decimals=0, base=pi):
	if n < 0:
		return '-' + converter(-n, decimals, base)
	result = ''
	digits = 0
	while n >= base ** digits:
		digits += 1
	for i in range(digits - 1, -decimals - 1, -1):
		div = n / base ** i
		integer = math.floor(div)
		n = n - integer * base ** i
		result = result + numbers[int(integer)]
	if decimals > 0:
		result = result[:-decimals] + '.' + result[-decimals:]
	if result[0] == '.':
		result = '0' + result
	return result


from math import pi, log, floor

def converter(n, decimals=0, base=pi):
	if n < 0:
		isNegative = True
		n *= -1
	else:
		isNegative = False
	if n == 0:
		digits = 1
	else:
		digits = floor(log(n) / log(base) + 1)
	piggyBank = n
	base36 = {10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F', 16: 'G', 17: 'H', 18: 'I', 19: 'J', 20: 'K', 21: 'L', 22: 'M', 23: 'N', 24: 'O', 25: 'P', 26: 'Q', 27: 'R', 28: 'S', 29: 'T', 30: 'U', 31: 'V', 32: 'W', 33: 'X', 34: 'Y', 35: 'Z'}
	output = ''
	power = digits - 1
	debugList = []
	while power >= 0:
		newDig = floor(piggyBank / base ** power)
		piggyBank -= newDig * base ** power
		if newDig >= 10:
			newDig = base36[newDig]
		output += str(newDig)
		power -= 1
	if decimals > 0:
		output += '.'
	while power * -1 <= decimals:
		newDig = floor(piggyBank / base ** power)
		piggyBank -= newDig * base ** power
		if newDig >= 10:
			newDig = base36[newDig]
		output += str(newDig)
		power -= 1
	if isNegative:
		output = '-' + output
	return output


from math import pi

def converter(n, decimals=0, base=pi):
	if n < 0:
		return '-' + converter(-n, decimals, base)
	CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	res = ''
	ln = 1
	while base ** ln <= n:
		ln += 1
	while 0 < ln:
		ln -= 1
		d = int(n / base ** ln)
		res += CHARS[d]
		n -= d * base ** ln
	if 0 < decimals:
		res += '.'
		base2 = 1
		while 0 < decimals:
			base2 *= 1 / base
			d = int(n / base2)
			res += CHARS[d]
			n -= d * base2
			decimals -= 1
	return res


from math import pi
digs = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def converter(n, decimals=0, base=pi):
	neg = ''
	ans = ''
	if n < 0:
		neg = '-'
		n = -n
	for i in range(20, -20, -1):
		if i == -1 - decimals:
			break
		if i == -1:
			ans += '.'
		d = int(n / base ** i)
		ans += digs[d]
		n -= d * base ** i
	while len(ans) > 1 and ans[0] == '0' and (ans[1] != '.'):
		ans = ans[1:]
	return neg + ans


from math import pi
import math

def converter(n, decimals=0, base=pi):
	print(n)
	print(decimals)
	print(base)
	negative = False
	retVal = ''
	if n == 0:
		left = 0
	else:
		if n < 0:
			n = n * -1
			negative = True
			retVal = '-'
		left = math.floor(math.log(abs(n)) / math.log(base))
	charList = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
	for p in range(left, 0 - decimals - 1, -1):
		if p == -1:
			retVal += '.'
		coeff = math.pow(base, p)
		print('XXXXXXXX')
		print(n)
		print(coeff)
		print('XXXXXXXX')
		print(math.floor(n / coeff))
		retVal += charList[math.floor(n / coeff)]
		n = n - math.floor(n / coeff) * coeff
	print(retVal)
	return retVal