Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2012
    Posts
    16

    Question Unanswered: Using decimal data type to work with monetary values

    Hi,

    I have a database that has several fields of decimal type to work with monetary values. Now I see that there are some problems using it, like the 9.20 value displays the value 9.19. I need to change all the fields in my database to DECFLOAT or is there a function or other alternative to solve it?

    Thanks,
    Davis

  2. #2
    Join Date
    Apr 2012
    Posts
    1,034
    Provided Answers: 18
    Always post your DB2-version+fixpack, and operating system of server/client.

    What do you mean exactly "displays the value..."?

    Do you mean in plain SQL at the command-line/Command-editor?
    Or do you mean when displayed by some front-end tool or in some browser that has done type conversion from decimal ?

    The stored value depends where and how you perform the rounding action (of any calculations) before insert/update of the DECIMAL column.

    What is your precise motivation for changing to DECFLOAT?

    In v9.7 & v10.1 a decimal is castable to a decfloat, so (subject to the documented restrictions of alter-table--alter-column) should be possible to do it - but depending on your motivation it may or may not resolve your issue.

  3. #3
    Join Date
    Mar 2012
    Posts
    16
    Sorry,

    I'm using DB2 9.7 Express-C in a Windows 7 64.
    The wrong value is only displayed in my front-end. I'm using delphi.
    In another front-end like IBM Data Studio I see that the value is correct.
    When I edit the value in a front-end built with Delphi the 9.2 value is displayed as 9.19999980926514.

    It's a problem with delphi only. I will post this error in a delphi forum.

    Thanks,
    Davis

  4. #4
    Join Date
    Apr 2012
    Posts
    1,034
    Provided Answers: 18
    If your Delphi datatype is currency, you might want to check out FMTBcd.BCDToCurr

  5. #5
    Join Date
    Sep 2004
    Location
    Belgium
    Posts
    1,126
    Quote Originally Posted by sdavis View Post
    When I edit the value in a front-end built with Delphi the 9.2 value is displayed as 9.19999980926514.
    This won't be solved by switching to DECFLOAT. To the contrary, chances are that Delphi won't understand that datatype...
    --_Peter Vanroose,
    __IBM Certified Database Administrator, DB2 9 for z/OS
    __IBM Certified Application Developer
    __ABIS Training and Consulting
    __http://www.abis.be/

  6. #6
    Join Date
    Mar 2012
    Posts
    16
    Solved. The error was being caused by the field type in the database. In the database was as real data type, not decimal. I changed to decimal (X, 2), now on the front-end is ok.
    And Delphi does not really recognize the type of field DECFLOAT.

    Thanks to all.
    Davis

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •