Consulting

Results 1 to 5 of 5

Thread: 2 dec. places becomes more than 2 dec. places!

  1. #1
    VBAX Regular
    Joined
    Dec 2007
    Posts
    78
    Location

    2 dec. places becomes more than 2 dec. places!

    I declare variable X as single, populate it with a calculated (e.g.) 14.02.
    I put it in a cell (the cell says 14.02).
    I format the cell as "0.00" (the cell says 14.02).
    Later, in another macro, I copy that cell value to another single variable, Y (according to the debugger, the variable says 14.02).
    I create a new spreadsheet and format the numbers as "0.00"
    I populate one of the cells I just formatted with the variable value, like this...
    Worksheets("Overall standings").Cells(driver_row, event_column).Value = Round(score, 2)
    The value in the cell now reads (e.g.) "14.01564333756".

    I've tried using "round(variable, 2)" on both X and Y (even though I can see they're only 2 dec. places), still no joy.

    Funny thing is, if I were to originally assign X a value of (e.g.) 16.5, I don't have the subsequent problem.

    Anyone come across similar?

  2. #2
    VBAX Tutor lynnnow's Avatar
    Joined
    Jan 2005
    Location
    Mumbai, Maharashtra, India
    Posts
    299
    Location
    why not just use the value from the variable instead of using the round syntax? Is "score" a calculated value or something that is a product of some calculation?

  3. #3
    VBAX Regular
    Joined
    Dec 2007
    Posts
    78
    Location
    Quote Originally Posted by lynnnow
    why not just use the value from the variable instead of using the round syntax?
    ...already tried both with and without the round syntax (sorry, I should've been clearer), same problem exists.

    Is "score" a calculated value or something that is a product of some calculation?
    Score is the variable that picks up the 14.02 value from the originally populated cell.

    Thanks for replying

  4. #4
    VBAX Tutor lynnnow's Avatar
    Joined
    Jan 2005
    Location
    Mumbai, Maharashtra, India
    Posts
    299
    Location
    declare the variable as Double instead of Single.

  5. #5
    VBAX Regular
    Joined
    Dec 2007
    Posts
    78
    Location
    Quote Originally Posted by lynnnow
    declare the variable as Double instead of Single.
    thx...that worked (rapidly moving on to the next problem)

Posting Permissions

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