Reputation: 75
I'm getting this error and not entirely sure why. In one class I create an object with the following line of code:
StoreSale sale = new StoreSale(1, 13.99);
The constructor inside the StoreSale class looks like this:
public StoreSale(int quantity, float value)
{
this.quantity = quantity;
this.value = value;
}
...and I'm getting the error 'The best overloaded method match for 'applicationname'.StoreSale.StoreSale(int, float) has some invalid arguments.'
Could anybody advise me as to what I'm doing wrong?
Upvotes: 1
Views: 2575
Reputation: 14894
You get this error because the literal 13.99
is a double
, and there is no implicit conversion from double
to float
. Use 13.99F
instead.
StoreSale sale = new StoreSale(1, 13.99F);
Upvotes: 3
Reputation: 354714
13.99
is a double literal. Append an f
to make it a float: 13.99f
.
In any case, you probably don't want to use binary floating-point for monetary values anyway. decimal
is a far saner choice.
Upvotes: 12