Variable: float

Just starting out? Need help? Post your questions and find answers here.
rolstra
User
User
Posts: 11
Joined: Mon Mar 24, 2008 10:44 pm
Location: Austria

Variable: float

Post 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.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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)) 
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
rolstra
User
User
Posts: 11
Joined: Mon Mar 24, 2008 10:44 pm
Location: Austria

Post by rolstra »

:-))

tricky, tricky .... :P

Thanks a lot.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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.
oh... and have a nice day.
Post Reply