Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...