C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
ToFeetInches: The ToFeetInches method receives a double of the number of total inches.
DoubleInfo: The feet part is the Key of a KeyValuePair. And the inches part is the Value.
KeyValuePairNote: The feet is an integer computed by dividing by 12. The inches part is computed with modulo division.
C# program that converts to feet and inches
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
var result = ToFeetInches(70.0);
Console.WriteLine(result);
result = ToFeetInches(61.5);
Console.WriteLine(result);
result = ToFeetInches(72.0);
Console.WriteLine(result);
}
static KeyValuePair<int, double> ToFeetInches(double inches)
{
return new KeyValuePair<int, double>((int)inches / 12, inches % 12);
}
}
Output
[5, 10]
[5, 1.5]
[6, 0]
So: Instead of 70 inches, you could display 5 foot 10. This is more familiar for some users.