Free Pascal Lazarus App Tutorial 6 - Simple Calculator Part 2 - String Conversion


User input with editboxes are entered as a string datatype. The computer can not perform calculate using strings. The computer needs numbers in an integer or floating point datatype to make mathematical calculations. The solution is to convert the string into an integer or floating point number, perform the calculation, then convert the calculation back to a string so the answer can be displayed in the editbox or label.

IntToStr() - Converts an Integer to a String
StrToInt() - Converts a String to an Integer

FloatToStr() - Converts a Floating Point to a String
StrToFloat() - Converts a String to a Floating Point

Example
Label1.Text := FloatToStr(StrToFloat(Edit1.Text) + StrToFloat(Edit2.Text));

Simple Calculator Tutorials

Tutorial 5 - Setting up the Form - Simple Calculator Part 1

Tutorial 6 - String Conversion - Simple Calculator Part 2

Tutorial 7 - RadioButtons - Simple Calculator Part 3

Tutorial 8 - Try Except Error Handling - Simple Calculator Part 4

Tutorial 9 - Tabs and Finished App - Simple Calculator Part 5

Code Download
SimpleCalculator.zip