First page Back Continue Last page Overview Text
Notes:
First, import the decimal package. (You can use “import from” if you prefer.) Integers are, of course, just decimals with no digits after the decimal point, so you can create instances from int or long objects. And then there's the most commonly used constructor: strings. (It works for unicode too.)
There is NOT a way to construct from float. This is so you don't accidently introduce unintended representation errors.
The construction from string is the one you'll probably use 90% of the time. And that's not as limiting as it sounds. If you think about it, most numbers are either calculated, or are input from the user, from a file, or perhaps some kind of database. In all of these cases, converting from string works great. It's only for constants in the source code that it looks awkward.