How to convert integer whole value to 3 digit dot seperated string
Just assign your integer value to a float and divide by 100.0.
Use Format() or FormatFloat() to convert the value to a string with three digits and a decimal point:
program Project8;
{$APPTYPE CONSOLE}
uses
System.SysUtils;
var
i : Integer;
const
myFormat : TFormatSettings = (DecimalSeparator: '.');
begin
i := 1230;
WriteLn(Format('v%4.1f',[i/100.0],myFormat)); // Writes v12.3
WriteLn(FormatFloat('v##.#',i/100.0,myFormat)); // Writes v12.3
ReadLn;
end.
I personally don't much care for using floating point arithmetic (the divide by 10 approach seen in other answers) when integer arithmetic can do the job. You are converting the number to an imperfect representation and then rounding to one decimal place. These solutions will work, because you can put a sufficiently tght bound on the representation inaccuracy. But why even fire up the floating point unit when the arithmetic can be done exactly using integer operations?
So I would always opt for something on these lines.
Major := Version div 100;
Minor := (Version mod 100) div 10;
Where Version
is your input value. This can then be converted into a string like so:
VersionText := Format('%d.%d', [Major, Minor]);
You can even do the conversion without any explicit arithmetic:
VersionText := IntToStr(Version);
N := Length(VersionText);
VersionText[N] := VersionText[N-1];
VersionText[N-1] := '.';
I am not sure if there is a cleaner or better way, but my suggestion would be to use copy in conjunction with IntToStr.
var
number,version:string;
begin
number = IntToStr(1850);
version = 'V'+copy(number,1,2)+'.'+copy(number,3,1);
end;
You are free to add checks of the length of the number
string, depending on your input values.