TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to VBNET

VB.NET Convert Miles to Kilometers

Convert miles, kilometers. It is possible to convert figures in miles to kilometers. The reverse from kilometers to miles is also available. We use a simple Double multiplication. We look at these conversion Functions in the VB.NET programming language.Double
Example. We introduce two Functions: ConvertMilesToKilometers, and ConvertKilometersToMiles. In each Function body, the argument is multiplied by a constant value and that result is returned from the Function.

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
Console.WriteLine. Let us note the Console.WriteLine function calls. They use a format string: the {0} is a substitution marker and the second argument to WriteLine is inserted there.

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.

Console
Summary. Numeric conversions, such as from miles to kilometers, are easily done in the VB.NET language. Typically, the Double type is good for these, as it retains more significant digits in a multiplication expression than does the Integer type.

Finally: For verification that these conversions are correct, please see the alternative version of this article.

C# Convert Miles
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf