Skip to content

Commit

Permalink
Modernize tagDEC definition. (#600)
Browse files Browse the repository at this point in the history
* Add `sign` local variable.

* Use f-string instead of `format`.

* add type annotations to `tagDEC.as_decimal`.
  • Loading branch information
junkmd committed Aug 13, 2024
1 parent 8e90051 commit 6a31de3
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions comtypes/automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,16 @@ class tagDEC(Structure):
("Lo64", c_ulonglong),
]

def as_decimal(self):
def as_decimal(self) -> decimal.Decimal:
"""Convert a tagDEC struct to Decimal.
See http://msdn.microsoft.com/en-us/library/cc234586.aspx for the tagDEC
specification.
"""
digits = (self.Hi32 << 64) + self.Lo64
decimal_str = "{0}{1}e-{2}".format(
"-" if self.sign else "",
digits,
self.scale,
)
return decimal.Decimal(decimal_str)
sign = "-" if self.sign else ""
return decimal.Decimal(f"{sign}{digits}e-{self.scale}")


DECIMAL = tagDEC
Expand Down

0 comments on commit 6a31de3

Please sign in to comment.