秒から分に変換するには、60.0で分割する必要があります(小数点が必要な場合、または整数のように扱われます)。整数のように扱い、30秒を渡すと30/60は0になります。
double.TryParse
メソッドも使用します。今、誰かが1.50xxを入力すると、アプリケーションがクラッシュします。 double.TryParse
メソッドを使用するか、try catchメカニズムを使用するか、数値入力のみを許可してください。
EDIT
これは、あなたが望むものを達成します。出力を表示するラベルを追加しましたが、削除することができます。
double enteredNumber;
if (double.TryParse(minTosecTextBox.Text, out enteredNumber))
{
// This line will get everything but the decimal so if entered 1.45, it will get 1
double minutes = Math.Floor(enteredNumber);
// This line will get the seconds portion from the entered number.
// If the number is 1.45, it will get .45 then multiply it by 100 to get 45 secs
var seconds = 100 * (enteredNumber - Math.Floor(enteredNumber));
// now we multiply minutes by 60 and add the seconds
var secondsTotal = (minutes * 60 + seconds);
this.labelSeconds.Text = secondsTotal.ToString();
}
else
{
MessageBox.Show("Please enter Minutes");
}
EDIT 2
いくつかの更なる明確化
あなたがいたならば、1.5(1分半)が90秒に等しくなるので、あなたは秒に分を変換されていません。これは論理的で明白です。 10進数の前の部分のみを分として扱い、10進数の後の部分を秒として扱います(1.30 = 1分、30秒= 90秒)。 したがって、小数点より前の部分を秒に変換し、小数点以下の部分を追加する必要があります。
1.5分、すなわち1分半は、90秒に対応する正しいです... –
1分は60秒です。したがって、 '1.5 * 60 = 90' –