I am currently in the process of translating Delphi code into Java code, and I need some help understanding what a certain line of code does. I have looked around online and cannot find what this specific part of the code does.
I understand what Writeln(...) from below does. I also understand that 'f' is the destination of the writeln(...) from the code below. I also understand what the FloatToStrF(...) function and its parameters are, but I am confused about the small piece attached to the end of the FloatToStrF(...):12 as seen below.
Writeln (f,FloattoStrF (llat,ffFixed,8,2):12,FloatToStrF(llon,ffFixed,8,2):12,InttoStr(elev):12,' ',zz);
What does the ':12' mean when attached to the end of FloatToStrF(...) or to InttoStr(...)? Does that mean what type it is? Is its type being changed to '12'? I know ' : ' is used for specifying types of variables in delphi, but what is it doing in this instance behind a FloatToStr(...)?
If a little more context is needed then here is a bit more of the code:
AssignFile(F, AppPath+'\Markov98.ctl');
Rewrite(F);
Writeln (f,FloattoStrF (llat,ffFixed,8,2):12,FloatToStrF(llon,ffFixed,8,2):12,InttoStr(elev):12,' ',zz);
CloseFile(F);
This is a width specifier. It is standard pascal and available in every pascal dialect.
For each value that you want to write out you can specify a width and (for float values) a precision:
writeln(f, 'Hi':5, 3.14159:7:2);
See the Delphi documentation: http://docwiki.embarcadero.com/Libraries/en/System.Write (or the FreePascal documentation http://wiki.lazarus.freepascal.org/Formatting_output)
The Writeln procedure is a compiler magic function and is just an extension of the Write procedure, After executing Write, Writeln writes an end-of-line marker.
Now what you looking for is explained in the documentation of the System.Write procedure
A Write(Ln) parameter has the form:
OutExpr [: MinWidth [: DecPlaces ] ]
MinWidth specifies the minimum field width, which must be greater than 0. Exactly MinWidth characters are written (using leading blanks if necessary) except when OutExpr has a value that must be represented in more than MinWidth characters. In that case, enough characters are written to represent the value of OutExpr. Likewise, if MinWidth is omitted, then the necessary number of characters is written to represent the value of OutExpr.
DecPlaces specifies the number of decimal places in a fixed-point representation of one of the Real types. It can be specified only if OutExpr is one of the Real types, and if MinWidth is also specified. When MinWidth is specified, it must be greater than or equal to 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With