C# Float Double problem.

Jelmer

Regular
Joined
Jan 11, 2006
Messages
96
A little problem in C#.Net

I've got a class with 2 functions:

Code:
        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:

Code:
prijs = stats.incltoexcl(prijs, BTW);

The full code:

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
 
Solved !!

Code:
        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
 
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.
 
Back
Top