# Convert float price to integer price without commas

My payment gateway wants the prices this way: "1050" instead of 10.50. So I created this function:

https://repl.it/HgHI/3

def price_format_gateway(price):
price = "{0:.2f}".format(price)
price = price.split(".")
try:
if len(price) > 2:
decimals = str(price[0:2])
else:
decimals = price
except IndexError:
pass

return str(price) + str(decimals)

price_format_gateway(10) # Expected -> 1000
price_format_gateway(10.1) # Expected -> 1010
price_format_gateway(10.15765) # Expected -> 1016


Is there another way more elegant, or cleaner? I just want to improve.

When you want to round a number to a specific number of digits, instead use round. Here you can use round(price, 2). The string format performs this too, so, if you perform the string format to force two decimal places, you can get the number rounded to two decimals separated by a period. I.e 10.16. You then just want to remove the period, and so you can just use '10.00'.replace('.', ''), and so you can drastically simplify this to:
def price_format_gateway(price):

def price_format_gateway(price):