1

Please help: I have two edit boxes on my form. The first one I use to type in an amount. The second one I use to divide the amount with. The problem is I try a number with a decimal like 5.5 and I keep on getting the error: "'5.5' is not a valid integer value".

Here is the code that I use:

var igroei,ipen, iper : integer;
    rgroei, rper : real;

begin
   ipen := strtoint(edtpen.Text); //the amount enter like 35060
   iper := strtoint(edtper.Text); // The number use for the percentage like 5.5
   iper := iper div 100;
   rgroei := ipen + iper;
   pnlpm.Caption := floattostrF(rgroei,ffcurrency,8,2);
end;

Thank you

1
  • 1
    StrToInt means STring TO INTeger, and integers don't have decimal places. You should learn the difference between integers and floating point types, and use the appropriate functions (StrToInt and StrToFloat) as needed. Commented Sep 17, 2015 at 17:24

1 Answer 1

6

5.5 is indeed not a valid integer. It is a floating point value. Use StrToFloat() instead of StrToInt(), and use Extended instead of Integer for the variable type.

var
  ipen, iper, rgroei : Extended;
begin
  ipen := StrToFloat(edtpen.Text); //the amount enter like 35060
  iper := StrToFloat(edtper.Text); // The number use for the percentage like 5.5
  iper := iper / 100.0;
  rgroei := ipen + iper;
  pnlpm.Caption := FloatToStrF(rgroei, ffcurrency, 8, 2);
end;

You should read the following to get started:

Integer and floating point numbers: The different number types in Delphi

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. Will use the Extended next time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.