LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I convert float number to string in Labwindows/CVI5.5?

Now I am programming to control the Magnet Power Supply (PS120-3, oxford instruments). It has its own command syntax. Such as if you want to set the sweep rate, you should send "Snnnnn", The parameter nnnnn is the required 5 digits, such as "00123" to stand for 1.23 Tesla/Min.
Now I need to increase the sweep rate gradually, from 1.10 to 1.20, 1.30, 1.40, etc. so I need to convert the float number to string to send the command.But now I can't find a function in the Labwindows/CVI to fulfill this conversion. From one of the C language book, I found a function, named ecvt, gcvt, fcvt, which can convert number to string, but they are not included in Labwindows/CVI5.5.
could you please give me some suggestion?
thanks.
0 Kudos
Message 1 of 2
(3,743 Views)
The fastest way is to use standard c sprintf command.
The syntax for your present problem is:
sprintf (string, "%05.0f", floatVal * 100.0);
if floatVal = 1.23 => string = "00123".
In this case sprintf performs the usual rounding, so that if floatVal = 1.236 string will be "00124".

In case you won't use sprintf, the same can be achieved (with slightly different formatting code) with Fmt function in the Formatting and I/O Library that ships with CVI.

Hope this helps
Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 2
(3,743 Views)