2017-03-18 8 views
0

丸めに問題があります。私はユーザーによって入力された2つの数字を分割します。私は常に「0」または整数のいずれかを取得します。C#の小数点以下3桁の数字

waistMeasurmentheightMeasurmentintているので、おそらくです
public static void GetRatios()//This method attains the users ratio inputs 
{ 
    double ratioCalc = waistMeasurment/heightMeasurment; //Calculates the ratio 
    ratio = Math.Round((Decimal)ratioCalc, 3, MidpointRounding.AwayFromZero); //Round the answer to 3 decimal places 'ratio' is initialised in the class 
} 
+0

'ダブルratioCalc =(ダブル)waistMeasurment/heightMeasurment' – dotctor

+0

病気私の投稿を更新してください。 – BobFisher3

+0

@doctorは完璧に動作しました。みんなありがとう! – BobFisher3

答えて

1

doubleにキャストすると、結果はdoubleになります。

あなただけの(@doctorのようにコメントに書いた)浮動小数点除算を持つために倍増するとそのうちの一つをキャストする必要があります。

double ratioCalc = (double)waistMeasurment/heightMeasurment; 
+0

ああ、それは意味があります、どうすればいいですか? – BobFisher3

+0

は答えを更新しました –

関連する問題