C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Note: This provides a close approximation of your distance in the opposite unit.
VB.NET program that converts miles and kilometers
Module Module1
Function ConvertMilesToKilometers(ByVal miles As Double) As Double
Return miles * 1.609344
End Function
Function ConvertKilometersToMiles(ByVal kilometers As Double) As Double
Return kilometers * 0.621371192
End Function
Sub Main()
Dim milesValues() As Double = {200.0, 310.7}
For Each value As Double In milesValues
Console.WriteLine("{0} miles -> {1:0.0} km", value, ConvertMilesToKilometers(value))
Next
Dim kilometersValues() As Double = {321.9, 500.0}
For Each value As Double In kilometersValues
Console.WriteLine("{0} km -> {1:0.0} miles", value, ConvertKilometersToMiles(value))
Next
End Sub
End Module
Output
200 miles -> 321.9 km
310.7 miles -> 500.0 km
321.9 km -> 200.0 miles
500 km -> 310.7 miles
And: The {1:0.0} marker is where the third argument is inserted. The 0.0 part specifies one digit after the decimal place is displayed.
ConsoleFinally: For verification that these conversions are correct, please see the alternative version of this article.
C# Convert Miles