INPUT$ versus INPUT

Community Forums/General Help/INPUT$ versus INPUT

gpete(Posted 2017) [#1]
Call me Captain Obvious.... but looking in the Command Help for "INPUT" only gave a description of "INPUT$"... That is misleading!

you can prompt for a value with- X%=INPUT(" give me the value of X -->")

for example- This works............

Function edit(thing.stuff)
thing\xsz=Input("x zize->")
thing\ysz=Input("y size->")
thing\zsz=Input("z size->")
KUBE=CreateCube()
EntityColor KUBE,255,100,255
EntityAlpha KUBE,.3
PositionEntity KUBE,-70,30,20
ScaleEntity KUBE,thing\xsz,thing\ysz,thing\zsz,True
End Function


Zethrax(Posted 2017) [#2]
The Input function returns a string value. The string data-type '$' tag is optional (this is the case for all function data-type tags).

If you pass the resulting string value to a numeric variable, function, etc then the string value will get converted to its numeric equivalent as near as it's possible to convert it. The conversion algorithm will try to convert the string characters until it finds one that doesn't work as a numeric character (the floating point dot for floats will get parsed) and then it will stop parsing. If there are no numeric characters to convert then the resulting number will be a zero.


gpete(Posted 2017) [#3]
Are you saying you cannot enter float values as a Input value?

so that 260.99 will be 260 ???


RemiD(Posted 2017) [#4]
try it !
value$ = input$() ;ten
or
value% = input$() ;10
or
value# = input$() ;10.5
then
debuglog("value = "+value)


Zethrax(Posted 2017) [#5]
Are you saying you cannot enter float values as a Input value?


To quote the thing that I wrote in plain english.
The conversion algorithm will try to convert the string characters until it finds one that doesn't work as a numeric character (the floating point dot for floats will get parsed) and then it will stop parsing.


Print "Enter an integer number (eg. 123)."
a% = Input( "" )
Print "Integer Value: " + a%

Print

Print "Enter a floating point number (eg. 1.23)."
b# = Input( "" )
Print "Float Value: " + b#

Print

Print "Press any key to exit."
WaitKey
End



RemiD(Posted 2017) [#6]
So the answer is yes, you can get an integer value or a float value using input().


gpete(Posted 2017) [#7]
thanks- so I tried the various things-

Using the input value of 123.9999 for each
Integer returns 123
Floating point returns 124.0

Using the input value of 123.999 for each
Integer returns 123
Floating point returns 123.999

Using the input value of 123.99 for each
Integer returns 123
Floating point returns 123.99

So it recognizes float values to 3 significant decimal values.


Zethrax(Posted 2017) [#8]
Bear in mind that the Input command accepts and outputs strings. Unless you're inputing funky non-ASCII characters or some character that it can't parse then what you get out is what you put in. Any difference in the float number is caused by the string to numeric conversion routine not the Input function.

The conversion routine seems to allow five fractional digits and rounds any excess digits off to the nearest value. If you entered 1.999999 then you'd get back 2.0 as the sixth digit gets rounded up which results in a cascade that results in all the fractional digits being rounded up. If you entered 1.99999 then that's what you'd get back as there are no excess digits to round off.