Jelmer Posted March 2, 2006 Posted March 2, 2006 A little problem in C#.Net I've got a class with 2 functions: public double excltoincl(double bedrag, float btw) { double berekening; berekening = Math.Round(bedrag * (btw/100),2); return berekening; } public double incltoexcl(double bedrag, float btw) { double berekening; berekening = Math.Round((bedrag/(100+btw))*100); return berekening; } In the main form i call this functions. But i'll get this error: Cannot convert from 'double' to 'float', on this lines: prijs = stats.incltoexcl(prijs, BTW); The full code: private void berekenen() { stats = new Class_statistieken(); double prijs; double.TryParse(txtPrijs.Text, out prijs); double BTW; double.TryParse(cmbBTW.Text, out BTW); if (radioIncl.Checked) { txtIncl.Text = prijs.ToString(); prijs = stats.incltoexcl(prijs, BTW); txtExcl.Text = prijs.ToString(); } else { txtExcl.Text = prijs.ToString(); prijs = stats.excltoincl(prijs, BTW); txtIncl.Text = prijs.ToString(); } } First it was a float.. but that one gave me the same error. So i tried a double... but also errors :( Whats going wrong? Thnx.. Jelmer Quote
Jelmer Posted March 2, 2006 Author Posted March 2, 2006 Solved !! public double excltoincl(double bedrag, double btw) { double berekening; berekening = Math.Round(bedrag + (bedrag * (btw/100)),2); return berekening; } public double incltoexcl(double bedrag, double btw) { double berekening; berekening = Math.Round((bedrag/(100+btw))*100); return berekening; } i was forgotten to change the btw to an double :o Quote
Administrators PlausiblyDamp Posted March 2, 2006 Administrators Posted March 2, 2006 The variable BTW is declared as double but the parameter is a float - change it to float and you should be fine for those 2 lines. You will also need to modify the double.TryParse(cmbBTW.Text, out BTW) to use float.Parse to get a clean compile. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.