#region Weights
private double StoneToKg(double Stone, double pounds)
{
return (Stone * 14 + pounds) * 0.4535970244035199;
}
private double[] KgToStone(double p)
{
double T = (p * 0.1574714285714286);
double Stn = Math.Floor(T);
double Pounds = (T - Stn) * 14;
return new double[2] { Stn, Pounds };
}
#endregion
#region Heights
private double CmToM(double Cm)
{
return Cm * 0.01;
}
private double MToCm(double M)
{
return M * 100;
}
private double FeetToMeters(double Feet, double inch)
{
Feet *= 12;
return (Feet + inch) * 0.025399999961392;
}
private double[] MetersToFeet(double Meters)
{
double feet = Math.Floor(Meters * 3.2808399);
double inch = (Meters * 3.2808399) - Math.Floor(Meters * 3.2808399);
inch *= 12;
return new double[2] { feet, inch };
}
private double feetInchToCentimeters(double feet, double inch)
{
return MToCm(FeetToMeters(feet, inch));
}
private double[] CentimetersToFeetInch(double Cm)
{
return MetersToFeet(CmToM(Cm));
}
#endregion
这是我正在使用的转换代码,目前在从石头转换为公斤并返回时遇到问题(100 stn 0 磅转换为公斤并返回 107 stn 和 2.00000000000014 磅)但将 100 公斤转换为石头并返回工作,我认为它是四舍五入答案,但我不确定在哪里或如何修复,寻找一种方法来进行准确的转换,可以处理往返的转换。
但是,欢迎任何其他代码绑定和建议。
(我包括了高度转换,以防万一也有问题)。