Results 1 to 3 of 3
  1. #1
    Join Date
    May 2004
    Posts
    34

    Cool Unanswered: Rounding problems

    I have rounding problems when editing or inserting a new record in float type fields.
    e.g. I have a cursor running an agrregate SQL statement. I have a calculated field Sum(DFactor*Cost). DFactor gets values -1,1 and values of Cost in the table have 2 digits. I get these values in a variable e.g. @FCost. Then I round @FCost=Round(@FCost,2).
    When I try to inert this value to a new record again I'using Round(@FCost,2).
    However in a lot of records a lot of digits are stored.
    I have the same probelm when trying to insert values from MSAccess by ODBC. Although I'm using CLng(@FCost*100)/100 in order to have 2 digits, a lot of demical values are created.
    What is the best practise in order to solve this problem?
    Regards,
    Manolis

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    If you are using a FLOAT column to store data of type MONEY, that's a problem. If you are using a FLOAT column to store data of type DECIMAL (x, 2), that's also a problem. Is your underlying problem one of datatype, not actually rounding?

    -PatP

  3. #3
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    Quote Originally Posted by Manolis Perakis
    Although I'm using CLng(@FCost*100)/100 in order to have 2 digits, a lot of demical values are created.
    The result will have decimals. You need this: CLng(@FCost*100/100)
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

Posting Permissions

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