Page 1 of 1

Variable: float

Posted: Fri Mar 28, 2008 6:29 pm
by rolstra
How can I display a floating variable (with decimales?):

zahl.f = Val(InputRequester("Input number: ", "Input number: ", ""))
MessageRequester("The number is: ", Str(zahl))

If I input e.g. 3.14 (or 3,14) the result is 3. But it should be 3.14 (or 3.14). Why does PB returns an integer?

Thanks, Roland.

Posted: Fri Mar 28, 2008 6:35 pm
by Sparkie
Welcome rolstra :)

ValF and StrF are your friends here. ;)

Code: Select all

zahl.f = ValF(InputRequester("Input number: ", "Input number: ", "")) 
MessageRequester("The number is: ", StrF(zahl,2)) 

Posted: Fri Mar 28, 2008 6:44 pm
by rolstra
:-))

tricky, tricky .... :P

Thanks a lot.

Posted: Fri Mar 28, 2008 8:20 pm
by Kaeru Gaman
welcome.

to keep Val() and Str() faster, it has no check for integer/float.
thus there are different functions for each type.
you normally know the type of a variable you pass to a function.
other languages have only one function with a typecheck.
more conveniant to the programmer, but less performant.