mercredi 12 février 2020

Random.nextDouble cannot convert to float(missing cast) C# [duplicate]

At the moment i am practicing interfaces, classes and inheritance. My problem seems to be the using of the method Random.nextDouble. With lower numbers it already worked, but when I take bigger values I receive following error.

Cannot implicitly convert type 'double' to 'float'. An explicit conversion exists (are you missing a cast?)

public Elephant()
{
  Speciemen = "Elephant";
  Enclosure = null;
  Cost = RndProps.RndAnimalPrice(500.00, 1000.00);
  Height = RndProps.RndAnimalHeight(1.00, 6.50);   
}

public double RndAnimalHeight(double minSize, double maxSize)
{
  return Rnd.NextDouble() * (maxSize - minSize) + minSize;
}

public double RndAnimalPrice(double minPrice, double maxPrice)
{
  return Rnd.NextDouble() * (maxPrice - minPrice) + minPrice;
}

As already mentioned it worked in the case with the RndAnimalHeight.




Aucun commentaire:

Enregistrer un commentaire