+ Reply to Thread
Results 1 to 4 of 4

Dim as Decimal?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-08-2006
    Posts
    203

    Dim as Decimal?

    I have a userform and I have been using
    (Dim cases as Integer) for some calculations

    What Dim do I use if I want the result to show as a partial?

    Example:
    txt =textbox input

    txtCasepack: 5
    txtQty: 16

    Dim cases as Integer

    cases = txtQty / txtCasepack

    Result: cases = 3

    Result I want: cases = 3.2

    Thank you

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Varient

    From the Help File

    Decimal data type
    A data type that contains decimal numbers scaled by a power of 10. For zero-scaled numbers, that is, numbers with no decimal places, the range is +/-79,228,162,514,264,337,593,543,950,335. For numbers with 28 decimal places the range is +/-7.9228162514264337593543950335. The smallest non-zero number that can be represented as a Decimal is 0.0000000000000000000000000001.

    Note that at this time the Decimal data type can only be used within a Variant. You cannot declare a variable to be of type Decimal. You can, however, create a Variant whose subtype is Decimal using the CDec function.

  3. #3
    Forum Contributor
    Join Date
    08-08-2006
    Posts
    203
    Variant seems to be working. Thank you

    I just used
    Dim cases As Variant

  4. #4
    Forum Contributor
    Join Date
    07-05-2006
    Location
    Canada
    MS-Off Ver
    2003, 2007
    Posts
    581
    Generally, it's a bad idea to use Variants when the same data can be captured by one of the other data types. The more frequently you use them, the slower in general your program will be.

    In this case, two alternatives are Single and Double.

    Dim x as Single
    Dim y as Double <-- Recommended

    You should almost always use the Double type for decimal numbers. It has both a larger range and higher precision. Since disk storage is generally cheap and RAM rather plentiful, there are really no advantages to using Single. (Of course, if you're dealing with some high volume application with specific conditions... maybe; but most everyday users will never encounter such a situation.)


    Scott

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1