Function
makereal
Purpose
Makes a real value from other types of values.
Return Type
real
Syntax
makereal(<type>(<value>))
Arguments
<type> Can be real, int, str, bool.
<value> A value of type <type>. This can be a constant,
variable, function call, expression, inline
command or a combination of these, together
resulting in a value of type <type>.
Return Value
A constant of type real. The <value>, whether it is a variable,
expression, or anything else, remains unchanged.
Stream Input
Streams apply to commands and not to functions.
Stream Output
Streams apply to commands and not to functions.
Stream Error
Streams apply to commands and not to functions, although any errors
will be written here.
Description
Depending on <type>, makereal() function performs
the type conversion as follows.
<type> Return Value
------- -------------------------------------------------------------
real The original real value is returned. (A copy of
the original real value is made.)
int A real value containing the int value appended with .0
is returned.
str If the str value contains a valid real constant,
then that constant is returned. Else, 0.0 is
returned.
bool 1.0 if the bool value is true, 0.0 otherwise.
Restrictions
Although any type can be converted to any other type using the makeXXXX() functions,
be careful, as it may sometimes produce unintended results.
All system functions are declared as global, and can not be redeclared (overloaded).
Valid Examples
var str s
var real itemPrice # The price of the item.
# ...
# s is assigned a string value based
# on some text in a file or on a web site.
set $itemPrice = makereal(str($s))
if ($itemPrice<>0.0)
echo "The item price is " $itemPrice "."
else
echo "The item price is not available."
endif
Will produce either the item price or an
indication that the item price is not available.
Invalid Examples
var str s
# ...
# s is assigned a string value based
# on some text in a file.
# We will assume that s does indeed
# contain correct real value.
var real r1
var real r2
set $r1 = $s # Automatic conversion.
set $r2 = makereal(str($s)) # Correct coversion.
$r1 assignment is incorrect, as it will be 1.0 if the
string is non-empty. Else, it will be 0.0. Thus, the
original real value in the string is not extracted.
$r2 assignment is correct, as it extracts the original
real value from the string.
See Also
constant
var
makeint
makestr
makebool
conversion
systemvar
|
© 2008-2013, biterScripting.com. All rights reserved.
biterScripting, biterScript, biterBrowser, biterMobile, biterScripting.com, FVA (Forward Variable Assignment) are trademarks of biterScripting.com. Is it biterScripting-compatible ? is a service mark of biterScripting.com.
Explorer, Unix, Windows are trademarks, service marks or other forms of intellectual property of their respective owners.
|