Valerie Meunier

Valerie Meunier

  • 969
  • 693
  • 72.1k

why doe not work when entering value with decimals?

Jun 15 2021 1:52 PM

Hi

I want to calculate the VAT on price.(21%).

when i enter an integer, it works: entering 10 gives 12.1

When i enter a value with 2 decimals, i get a wrong result: entering 10.5 gives 127.05 !!

All values are float, so why this error?

Thanks

 class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter price: ");
            float vat;
            float prijs = Convert.ToSingle(Console.ReadLine());
            vat = (float)(prijs * 0.21);
            Console.WriteLine("Prijs with vat: {0} ",prijs + vat);
        }
    }


Answers (1)