Results 1 to 5 of 5

Thread: How to get absolute value for floating number

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    How to get absolute value for floating number

    I have float number 2.11.

    How do I get the absolute value for this number?

    Code:
    Dim av As String
    av = Abs(2.11) <= 0.0005

  2. #2
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: How to get absolute value for floating number

    I'm a bit confused by what you mean, my understanding of an absolute value is just the value without sign i.e. AbsoluteValue = Abs(number)

    What do you mean?

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to get absolute value for floating number

    I have floating number 2.11 . In the field name it showed 2.11.. But absolutely it mybe 2.11324.. So I want to get the value after 2.11

    Abs(2.11 <= 0.0005)

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: How to get absolute value for floating number

    There's some confusion here. The Abs Function returns the unsigned magnitude of the argument. eg Abs(-1) = 1, Abs(1) = 1.

    You can adjust the number of decimal places displayed via the Format statement eg Debug.Print Format(sngNumber, "0.0000")

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: How to get absolute value for floating number

    Note also that most floating-point data types (such as Single and Double) do not store data accurately.

    It is possible that a number like 2.11324 would actually be stored as just 2.11, and if so there is no way to get the extra precision back.

    If you want floating-point numbers with accuracy, try using the Currency data type instead.

Posting Permissions

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



Click Here to Expand Forum to Full Width