Hi,
Im wondering is there any way to change a string (which is a number), to a float? or number?
For instance after you have used arraytostring() function, how do you turn the output into a number (if it is a number)?
It seems this new arraytostring() function turns everything into a string, with additional single quotes, and it's impossible to turn it back into a number again...
Cheers
float string to float?
-
- Regular
- Posts: 315
- Joined: 02 Nov 2013 11:19
Re: float string to float?
newtfish wrote:Hi,
Im wondering is there any way to change a string (which is a number), to a float? or number?
For instance after you have used arraytostring() function, how do you turn the output into a number (if it is a number)?
It seems this new arraytostring() function turns everything into a string, with additional single quotes, and it's impossible to turn it back into a number again...
Cheers
I guess the first question is - why are you using arraytostring()? If it is simply for display purposes, you can leave it as a number and use constructs like:
someStringVar = '' + myFloat;
to get a string.
If for whatever reason the number is represented as digits stored in an array, you have to loop through each array position converting the ASCII into a number. There are some examples where people display arrays as numbers. Basic idea is (if you know it is a number in the array) is that the number 0 is ASCII 30h (hex) and 9 is ASCII 39h, so subtracting 30h from the value gives you the number (value = arr[0] - 0x30;) Then you multiply by 1, 10, 100, etc and add the next number from the array. There's got to be at least one example of how this is done floating around the various templates and demos.