#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Firebird rounding decimals number


    Hi!
    I have a firebird database (vs. 2.5 RC2) with a table with ColumnA and ColumnB, both numeric, lenght 6, scale 2.
    I want to do ColumnA * ColumnB, but the rezult is numeric, 6, 4.
    Eg. ColumA 45,67
    ColumnB 33,38
    ColumA * ColumnB should be 45,67 * 33,38 = 1524,4646
    But i want 1524,46.
    How can do this.
    Please help me.
    Thanks!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2006
    Location
    Plovdiv. Bulgaria
    Posts
    224
    Rep Power
    12
    Originally Posted by banaru
    Hi!
    I have a firebird database (vs. 2.5 RC2) with a table with ColumnA and ColumnB, both numeric, lenght 6, scale 2.
    I want to do ColumnA * ColumnB, but the rezult is numeric, 6, 4.
    Eg. ColumA 45,67
    ColumnB 33,38
    ColumA * ColumnB should be 45,67 * 33,38 = 1524,4646
    But i want 1524,46.
    How can do this.
    Please help me.
    Thanks!
    round(ColumA * ColumnB,2)
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0
    Originally Posted by mIRCata
    round(ColumA * ColumnB,2)
    Thanks for you response.
    The result is 1524,4600
    Rounding is correct but is adding two zeros and i don't want.
    Whay?
    For editing firebird i use Database Workbench 4.0.3 but i have the same result in IBManager.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0
    Originally Posted by banaru
    Thanks for you response.
    The result is 1524,4600
    Rounding is correct but is adding two zeros and i don't want.
    Whay?
    For editing firebird i use Database Workbench 4.0.3 but i have the same result in IBManager.
    Someone please?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,055
    Rep Power
    383
    I suspect you need to look at the formatting properties of your tool.
    I probably is not a Firebird issue
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    1
    Rep Power
    0
    That depends on the data type of your column. You can cast to a decimal with two digits after the point in this way:

    cast( round(ColumA * ColumnB,2) as decimal(17, 2))
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    55
    Rep Power
    6

    Thumbs up


    Fields type NUMERIC behave cast.

    Thus, the problem in the result of the expression should not be at the Firebird, but, in the definition of the field or variable used to welcome such an outcome.

    Try the EDITOR OF FIELDS from Dataset, see the settings that are being used for PRECISION and SCALE. (size for anyone)

    Example: Fields type CURRENCY using SCALE = 4 for default in EDITOR FIELDS.

    As a general rule for multiplication, is the sum of the amount of decimal places when showering with parts number WHOLE AND DECIMAL. Example: * iiii.dd iii.ddd = ix.ddddd

    Thus, as the division is automatic use of regular tithe.
    1 / 3 = 0.3333333333...

    In Delphi, goes to 15 digits significants
    In Firebird, max 18 digits significats (see the version)

    For more information, look at Firebird Support FAQs

    http://www.firebirdfaq.org/faq340/

    http://www.firebirdfaq.org/ (Search for "NUMERIC")

    NOTE: In Delphi, you can use "MASK EDIT" for fields formatation.



    Last edited by emailx45; July 9th, 2013 at 10:23 AM.

IMN logo majestic logo threadwatch logo seochat tools logo