Results 1 to 7 of 7

Thread: Moving decimal

  1. #1

    Thread Starter
    Hyperactive Member High Octane's Avatar
    Join Date
    Aug 2003
    Location
    Texas
    Posts
    290

    Moving decimal

    I am getting value of 40836.0 generating from another program. Now I wanted to move decimal at -3, turning it into 40.8. How do I do this with code?

    I tried divididng by 1000 and I get round off to 41.0... Actually I want precise number "40.8. Anyone?
    High Octane

  2. #2
    Lively Member Hojo's Avatar
    Join Date
    Jul 2005
    Location
    Brisbane, Australia
    Posts
    119

    Re: Moving decimal

    Do you have the variable defined as an Integer or as a double or single?
    Despite body and mind, my youth will never die!

    Everytime I learn something new it pushes some old stuff out of my brain!

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Moving decimal

    This works for me

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Dim a As Long
    5. Dim b As Currency
    6. a = 40836
    7. b = a / 1000
    8. MsgBox Format(b, "###.#")
    9. End Sub

    prints 40.8

  4. #4

    Thread Starter
    Hyperactive Member High Octane's Avatar
    Join Date
    Aug 2003
    Location
    Texas
    Posts
    290

    Re: Moving decimal

    Anyone?
    High Octane

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Moving decimal

    Refresh your screen. I posted #3 a few minutes ago.

  6. #6
    Lively Member Hojo's Avatar
    Join Date
    Jul 2005
    Location
    Brisbane, Australia
    Posts
    119

    Re: Moving decimal

    As dglienna said,

    Number divided by 1000 formated to show 1 decimal place will work. You have to check if there is something in you code that is rounding your number.
    Despite body and mind, my youth will never die!

    Everytime I learn something new it pushes some old stuff out of my brain!

  7. #7
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Moving decimal

    High Octane


    This is what you want.


    VB Code:
    1. Option Explicit
    2.  
    3.  
    4. Private Sub Form_Load()
    5. Dim a As Long
    6. Dim b As Currency
    7. a = 40836
    8. b = CCur(a / 1000)
    9. MsgBox Format(b, "###.#")
    10. End Sub

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