Discussion:
how can I do the conversion from a string to a float
(too old to reply)
larche
2008-08-07 20:10:08 UTC
Permalink
Hi,
I need to take a string, which is the time and to convert it into a float, because the program I send it to is only receiving a float...how can I do that?
cschneider
2008-08-07 20:10:09 UTC
Permalink
In the strings-palette, there's a subpalette called "String/Number"-conversion...Just use Fract/Exp-String to Number to convert your string GreetingsChristian
smercurio_fc
2008-08-07 20:10:11 UTC
Permalink
It may not be as simple as that. Is the string simply the float value as a string (in which case you can do the above), or is it in a specific format?
larche
2008-08-07 20:10:11 UTC
Permalink
let me explain, if the time is the string 18;30;36 I want the float 183036 kind of
Cory K
2008-08-07 20:10:12 UTC
Permalink
well assuming the time is broken up by semicolons as you have shown,first, split up the time, using ";" as your split character.then, you have three segments: hours, minutes, seconds.
Then i would convert each of those (using string --> dbl or something like that)
Then you have 3 numbers to do whatever you would like with.
Cory K
2008-08-07 20:10:12 UTC
Permalink
well assuming the time is broken up by semicolons as you have shown,first, split up the time, using ";" as your split character.then, you have three segments: hours, minutes, seconds.
Then i would convert each of those (using string --> dbl or something like that)
Then you have 3 numbers to do whatever you would like with.
cschneider
2008-08-07 20:40:05 UTC
Permalink
There can be different approaches, just two of them: Use Scan from String to get the different parts of your string as Number or eliminate your ;;; from your string with "Search and replace string"...

<img src="Loading Image..."> Greetings,

ChristianMessage Edited by cschneider on 08-07-2008 11:13 PM


string1.png:
http://forums.ni.com/attachments/ni/170/347662/1/string1.png
Cory K
2008-08-07 20:40:05 UTC
Permalink
Heres the program that I was describing earlier (and accidentally posted twice oops)
&nbsp;


Time String to Number.vi:
http://forums.ni.com/attachments/ni/170/347663/1/Time String to Number.vi
corys
2008-08-07 20:40:06 UTC
Permalink
My contribution to the conversions...gives you a 1D array of 3 elements (one for each section of the string).<img src="Loading Image..."> Message Edited by corys on 08-07-2008 03:14 PM


ToDbl.PNG:
http://forums.ni.com/attachments/ni/170/347665/1/ToDbl.PNG
cschneider
2008-08-07 20:40:06 UTC
Permalink
Yeah, smercurio, I think so...that's why I posted that solution...
smercurio_fc
2008-08-07 20:40:05 UTC
Permalink
Scan From String is a lot easier, don't you think? :smileywink:
Cory K
2008-08-07 20:40:06 UTC
Permalink
Well, I just created the first method that came to mind.
Yes scan from string is a lot simpler, and less work.....either one works.
Actually, there are probably 10 other ways to do it, up to you.
larche
2008-08-07 20:40:07 UTC
Permalink
thanks for all the solutions, but I didn't explain well...sorry
I have three different boxes, one for each part of the string, one for the hours,one for the&nbsp;minutes and one for the seconds.
At the end, I want just one number, which will group the time together, example: 043006
corys
2008-08-07 20:40:08 UTC
Permalink
Something like this?<img src="Loading Image..."> Message Edited by corys on 08-07-2008 03:23 PM


ToNumber.PNG:
http://forums.ni.com/attachments/ni/170/347671/1/ToNumber.PNG
larche
2008-08-07 20:40:08 UTC
Permalink
yes exactly and if it's 4 o'clock for example, I want 04
corys
2008-08-07 21:10:05 UTC
Permalink
This seems like it has to be some Rube Goldberg code, but here's one way of doing it. (Note: The display format for the numeric indicator must be changed as shown in the picture, or else zeros before the hour will not show).<img src="Loading Image..."> <img src="Loading Image..."> Message Edited by corys on 08-07-2008 03:44 PM


SeeminglyGoldberg.PNG:
http://forums.ni.com/attachments/ni/170/347680/1/SeeminglyGoldberg.PNG


properties.PNG:
http://forums.ni.com/attachments/ni/170/347680/2/properties.PNG
larche
2008-08-07 21:10:06 UTC
Permalink
thanks a lot for your patience, it works find!!!
smercurio_fc
2008-08-07 21:40:05 UTC
Permalink
corys wrote:This seems like it has to be some Rube Goldberg code, ...You can simplify it this way:<img src="Loading Image..."> Message Edited by smercurio_fc on 08-07-2008 04:12 PM


Example_VI_BD6.png:
http://forums.ni.com/attachments/ni/170/347686/1/Example_VI_BD6.png
Loading...