1

No floats should be used to store prices in the database, but what with floats and land area?

I have for example:

$area1 = 101.12;
$area2 = 92.19;
$area3 = 104.02;
$area4 = 89.10;
$area5 = 95.58;

Can I use float in DB for these values? Then I would like to look after these values in the database, sometimes merge two values ($area1 + $area2) or calculate the average also.

What type in the database should I use?

If I use other than float then how can I type it in PHP?

function merge(float $area1, float $area2) : float

Then can I use float type?

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
sivuvok
  • 19
  • 1
  • The question is why would you want to do so? If the unit has a fractional part you could probably standardize the amounts to the lowest possible fraction and store it as an integer. e.g. meters => centimeters – Dharman Jun 16 '19 at 10:25
  • 1
    Possible duplicate of [Difference between float and decimal data type](https://stackoverflow.com/questions/5150274/difference-between-float-and-decimal-data-type) – Shadow Jun 16 '19 at 10:42
  • Sorry to point out, but you are asking the wrong question. Why? Your question is a business question, not a programming one. The honest answer is: yes, you can use float for any numeric data that has fractional value. However, float may not be the best data type, but we cannot really help you to decide what else to use because you did not ask a programming question. The programming question would list whatbexactly you want to do with the data and what results you expect from those operations. This is why I suggested the duplicate topic thatexplains the differences between float and decimal. – Shadow Jun 16 '19 at 10:50

0 Answers0