Results 1 to 3 of 3

Thread: How to increase decimal places in this function (Excel)

  1. #1

    Thread Starter
    Registered User
    Join Date
    Oct 2021
    Posts
    1

    How to increase decimal places in this function (Excel)

    Hi all, I found this function to convert Decimal Degrees to Degrees/Minutes/Seconds at this website (https://docs.microsoft.com/en-US/off...seconds-angles)
    Code:
    Function Convert_Degree(Decimal_Deg) As Variant
        With Application
            'Set degree to Integer of Argument Passed
            Degrees = Int(Decimal_Deg)
            'Set minutes to 60 times the number to the right
            'of the decimal for the variable Decimal_Deg
            Minutes = (Decimal_Deg - Degrees) * 60
            'Set seconds to 60 times the number to the right of the
            'decimal for the variable Minute
            Seconds = Format(((Minutes - Int(Minutes)) * 60), "0")
            'Returns the Result of degree conversion
            '(for example, 10.46 = 10~ 27  ' 36")
            Convert_Degree = " " & Degrees & " " & Int(Minutes) & " ' " & Seconds + Chr(34)
        End With
    End Function
    The only problem is I need the seconds number to two decimal places.

    E.g 38.93821121 converts to 38 56 ' 17". However I want it to show as 38 56 ' 17.56"

    If anyone knows how to modify the function it will be greatly appreciated. Thanks!
    Last edited by Shaggy Hiker; Oct 6th, 2021 at 08:32 AM. Reason: Added CODE tags.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,792

    Re: How to increase decimal places in this function (Excel)

    This appears to be VBA, not VB.NET, and so should have been posted in the Office Development forum. I have asked the mods to move it. Please don't double post in the meantime.

  3. #3
    Frenzied Member jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    1,941

    Re: How to increase decimal places in this function (Excel)

    https://docs.microsoft.com/en-us/off...r-applications

    Code:
     Seconds = Format(((Minutes - Int(Minutes)) * 60), "0.00")

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