title: How do I convert longitude and latitude to GPS Exif byte array
body: <p>I am trying to put latitude = 8°50'34.46" and longitude = 125° 9'50.82" into the exif file of an image. i'm using vb.net.</p>
  
  <p>I'm not having problem converting the degrees and minutes into bytes because it is a whole number but when i convert the seconds (34.46") which has decimal values into bytes. it gives different result like 0.9856.</p>
  
  <p>Please help me guys how to convert numbers with decimal values into bytes.</p>
  
  <p>here the code:</p>
  
  <pre><code>Private Shared Function intToByteArray(ByVal int As Int32) As Byte()
      ' a necessary wrapper because of the cast to Int32
      Return BitConverter.GetBytes(int)
  End Function
  
  Private Shared Function doubleToByteArray(ByVal dbl As Double) As Byte()
      Return BitConverter.GetBytes(Convert.ToDecimal(dbl))
  End Function
  
  Private Shared Function doubleCoordinateToRationalByteArray(ByVal doubleVal As Double) As Byte()
      Dim temp As Double
  
      temp = Math.Abs(doubleVal)
      Dim degrees = Math.Truncate(temp)
  
      temp = (temp - degrees) * 60
      Dim minutes = Math.Truncate(temp)
  
      temp = (temp - minutes) * 60
      Dim seconds = temp
  
      Dim result(24) As Byte
      Array.Copy(intToByteArray(degrees), 0, result, 0, 4)
      Array.Copy(intToByteArray(1), 0, result, 4, 4)
      Array.Copy(intToByteArray(minutes), 0, result, 8, 4)
      Array.Copy(intToByteArray(1), 0, result, 12, 4)
      Array.Copy(doubleToByteArray(seconds), 0, result, 16, 4)
      Array.Copy(intToByteArray(1), 0, result, 20, 4)
  
      Return result
  End Function
  </code></pre>