I have an integer representing a price in cents. Using Python format strings, how can I convert this value into dollars with two decimal places? Examples:
1234 => 12.34
5 => 0.05
999 => 9.99
EDIT: I should give some background. I am storing prices in a database as integers in order to make sure I don't loose precision. I don't want to use the Decimal datatype because these values will also be used in calculations in Javascript, so integers will be simplest to work with for that. I want to be able to display in a Django template the formatted value using the stringformat tag. As such, dividing the number by 100 doesn't work. Is there a way to add the decimal point without dividing?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…