We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › getting the datatype
Page Index Toggle Pages: 1
getting the datatype (Read 335 times)
getting the datatype
Nov 17th, 2006, 10:38am
 
hi,
im new, -and i searched the site.. yet havent found anything. im looking for a function that gives me
the datatype (int, string, float etc.) of a variable.

i thought it would be getType() , but i allways get errors however i put it.
xyz.getType() getType(xyz) etc.


does anyone know the right function? or at least what i need to import to make it work?

thanks,
a
Re: getting the datatype
Reply #1 - Nov 17th, 2006, 10:58am
 
I don't know how to determine if something is an int/float/byte/boolean, but for all Objects, there's .getClass() which will give you their Class, and instanceof to let you see if it's a perticular type of object.
Re: getting the datatype
Reply #2 - Nov 17th, 2006, 4:10pm
 
thanks for the tip, the variable is read and saved as a string so would always just get the string class in my case.

i guess i'll write my own little function analyzing each character to then convert it to the matching type..

Re: getting the datatype
Reply #3 - Nov 17th, 2006, 4:26pm
 
Ah right, well if it's a string, then yes, everything will just say "String" since that's what it is.

However both int() and float() can take a string and output the value, e.g.
Code:
int a=int("3.1412");
float b=float("3.1412");
println(a);
println(b);
Page Index Toggle Pages: 1