From Clomosy Docs
No edit summary |
No edit summary |
||
| Line 8: | Line 8: | ||
Let's say you have a variable i. The type of this variable is assigned as integer. The value of this variable can be given an integer value. Here we have given a negative value. Finally, abs function was used to get the absolute value. <br> | Let's say you have a variable i. The type of this variable is assigned as integer. The value of this variable can be given an integer value. Here we have given a negative value. Finally, abs function was used to get the absolute value. <br> | ||
:''' | :'''TRObject Syntax''' | ||
var | var | ||
i : Integer; | i : Integer; | ||
{ | |||
i | i = -1235; | ||
ShowMessage('Before: '+ IntToStr(i)); | ShowMessage('Before: '+ IntToStr(i)); | ||
//The absolute value of i is taken and put back to i. | //The absolute value of i is taken and put back to i. | ||
i | i = Abs(i); | ||
ShowMessage('After: '+IntToStr(i)); | ShowMessage('After: '+IntToStr(i)); | ||
} | |||
:'''Base Syntax''' | |||
var | var | ||
i : Integer; | i : Integer; | ||
begin | |||
i = -1235; | i := -1235; | ||
ShowMessage('Before: '+ IntToStr(i)); | ShowMessage('Before: '+ IntToStr(i)); | ||
//The absolute value of i is taken and put back to i. | //The absolute value of i is taken and put back to i. | ||
i = Abs(i); | i:= Abs(i); | ||
ShowMessage('After: '+IntToStr(i)); | ShowMessage('After: '+IntToStr(i)); | ||
end; | |||
Revision as of 10:37, 23 August 2024
function Abs(Number Numeric type):Numeric type;
Returns the absolute value of an integer.
Syntax:
value := Abs(value);
Example:
Let's say you have a variable i. The type of this variable is assigned as integer. The value of this variable can be given an integer value. Here we have given a negative value. Finally, abs function was used to get the absolute value.
- TRObject Syntax
var
i : Integer;
{
i = -1235;
ShowMessage('Before: '+ IntToStr(i));
//The absolute value of i is taken and put back to i.
i = Abs(i);
ShowMessage('After: '+IntToStr(i));
}
- Base Syntax
var
i : Integer;
begin
i := -1235;
ShowMessage('Before: '+ IntToStr(i));
//The absolute value of i is taken and put back to i.
i:= Abs(i);
ShowMessage('After: '+IntToStr(i));
end;