+ Reply to Thread
Results 1 to 4 of 4

Float to integer

  1. #1
    Forum Contributor
    Join Date
    09-02-2005
    Posts
    146

    Float to integer

    I'm creating a user form where the user can enter latitude and longitude in either Deg/Min/Sec format or Decimal Degrees.

    To go from decimal degrees into Deg/Min/Sec I need to do the following
    A=Decimal Degrees (Single)
    X=Degrees (Integer)
    Y=Minutes (Integer)
    Z=Seconds (Single)

    X = Integer(A) <-- I need to cast A as an integer or truncate it. Not sure how to do this in VBA.
    Y = Integer[( A - X ) * 60] <-- Again, needs to be cast as an integer
    Z = {[( A - X ) * 60] - Y} * 60

    I didn't see a native truncate function in Excel and in the past I've always used Left() or Right()

    How would y'all do this?
    Last edited by wilro85; 08-27-2009 at 07:50 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Float to integer

    Perhaps ...
    Please Login or Register  to view this content.
    Last edited by shg; 08-27-2009 at 06:30 PM.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    09-02-2005
    Posts
    146

    Re: Float to integer

    Very useful, but the use of MOD has changed in VBA. It is now # mod # instead of mod(#,#)

    Please Login or Register  to view this content.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Float to integer

    That's not VBA, they are worksheet formulas. Excel's MOD is a function, VBA's Mod is an operator.

    Also, your d/m/s variables should be Longs, not Singles. Otherwise, you're forcing VBA to do unnecessary type conversions.

    DecDeg should be a Double, because that's how it's stored on the worksheet.
    Last edited by shg; 08-27-2009 at 07:52 PM.

+ 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