Skip to content

Loss of scale when reading numeric with zero value #53

Closed

Description

@qweqq

Hello!

When reading a numeric column with zero value the scale of the numeric value is not preserved:

import firebird.driver as firebird
import decimal

con = firebird.connect('employee')
cur = con.cursor()
cur.execute("select cast('0.00' as NUMERIC(9,2)) from rdb$database")

val_from_db = cur.fetchone()[0]
val_from_py = decimal.Decimal('0.00')

val_from_db_str = format(val_from_db, 'f')
val_from_py_str = format(val_from_py, 'f')

print(val_from_db_str)
print(val_from_py_str)

assert val_from_db_str == val_from_py_str

cur.close()
con.close()

Output:

0
0.00
Traceback (most recent call last):
  File "/home/qweqq/test3.py", line 17, in <module>
    assert val_from_db_str == val_from_py_str

While investigating the issue I found that a python decimal.Decimal with zero value divided by anything does not change its scale:

import decimal
print(format(decimal.Decimal('0') / 1000, 'f'))

Output:

0

but if the zero value is scaled using the builtin scaleb method it works:

import decimal
print(format(decimal.Decimal('0').scaleb(-3), 'f'))

Output:

0.000

Regards,

Activity

  1. added 2 commits that reference this issue on Jul 25, 2025
    5a71600
    2b7040a
  2. added a commit that references this issue on Jul 26, 2025
    2ed1050
  3. pcisar commented on Jul 26, 2025

    @pcisar
    Contributor

    @qweqq Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions