I understand that I'm stupid, but ... What type of data to declare for a number of type 4.46 in Delphi?

    2 answers 2

    real , double , currency . It depends on what the variable is and what will happen to it.

      If the variable is not used for calculations related to cash transactions, where the error is critical, then it makes sense to choose Real or Double .

      I also note that if you choose any particular type for floating point operations, then use it everywhere in the project - that is, if Real , then Real , if Double , then everywhere Double (well, except with rare exceptions)

      You can read more about calculations with the Currency type here. This, however, is a description of a similar type in C #, but the meaning and problem domain remain the same.

      • 3
        I beg to differ. Types are different, types are important. Without knowing the features of the project, one cannot argue that everything should be just double or only real . Just for each task you need to choose the most suitable type and understand why it is selected. - Nofate
      • @Nofate This may be a matter of taste, but I am for commonality and one global real type (single or double precision). Justified cases where a piece of code uses the double type to increase accuracy, but the remaining code uses real / float can be counted on fingers. But to conduct permanent implicit type castings simply because somewhere a person decided to write a double , and somewhere real - this is nonsense. - Costantino Rupert
      • @Nofate Many game engines use the #define USE_DOUBLE_PRECISION type approach when all real types automatically become double or float , which is also very convenient. Similarly, for example, the /FP:fast and /FP:precise flags of the compiler cl ( Visual Studio ) also work. - Costantino Rupert
      • I tend to think that in general you need to use double and not to soar your brain. I think you won’t get the win from the float. If it is necessary to save memory, our choice is float. Another point - for some reason, the use of DX in C ++ leads to the stalling of all real arithmetic in SP. <a href= blogs.msdn.com/b/tmiller/archive/2004/06/01/…> > - gecube