LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Formatting a String

I'm new to Labview so this might be a simple one.

I'm trying to control a power supply on a com port. The problem I'm
having is when trying to set the voltage and current. The power supply
needs the string in the format of xx.xxx, it must have all 5 digits or
it will not recognize it as a valid command.

Here's the process I'm using.

First I read a control for the voltage setting from the front panel,
then use the "Format Value" function with a format string of %.3 to
convert the value to a string with 3 decimal places. This works fine for
any value over 10, but any lower value doesn't have the tens digit and
only outputs x.xxx. I need to get a leading 0 on anything under 10.

I've actually figured out a way to it by counting the out
put string
length and using an "Append true/false String", but this ends up messing
up the values over 10.

Is there another format string syntax that will force 2 places before
the decimal?

Thanks


Sent via Deja.com http://www.deja.com/
Before you buy.
0 Kudos
Message 1 of 7
(4,589 Views)
The correct format string is %06.3f

Martin

--
Martin Henz Systemtechnik
Dipl. Ing. (FH) Martin Henz
Rochenweg 1
70378 Stuttgart
Tel. ++49-711-5302605
Fax ++49-711-5058649
http://www.mhst.de
"Ed Dickens" schrieb im Newsbeitrag news:8v3nan$ohr$1@nnrp1.deja.com...
> I'm new to Labview so this might be a simple one.
>
> I'm trying to control a power supply on a com port. The problem I'm
> having is when trying to set the voltage and current. The power supply
> needs the string in the format of xx.xxx, it must have all 5 digits or
> it will not recognize it as a valid command.
>
> Here's the process I'm using.
>
> First I read a control for the voltage setting from the front panel,
> then use the "Format Value" function with a format string of
%.3 to
> convert the value to a string with 3 decimal places. This works fine for
> any value over 10, but any lower value doesn't have the tens digit and
> only outputs x.xxx. I need to get a leading 0 on anything under 10.
>
> I've actually figured out a way to it by counting the output string
> length and using an "Append true/false String", but this ends up messing
> up the values over 10.
>
> Is there another format string syntax that will force 2 places before
> the decimal?
>
> Thanks
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
0 Kudos
Message 2 of 7
(4,589 Views)
Thanks Martin, that did the trick, I figured it was simple.

One other quick question to see if I understand the format string.

It looks like this one breaks down as follows.

0 = left fill with 0
6 = bit count for the string, including the decimal
3 = number of decimal places
f = ???

I've looked through all my documentation and cannot find a description
of how the format strings or codes work. do you know where I can find
this info?


> The correct format string is %06.3f
>
> Martin
>
> --
> Martin Henz Systemtechnik
> Dipl. Ing. (FH) Martin Henz
> Rochenweg 1
> 70378 Stuttgart
> Tel. ++49-711-5302605
> Fax ++49-711-5058649
> http://www.mhst.de


Sent via Deja.com http://www.deja.com/
Before you buy.
0 Kudos
Message 3 of 7
(4,589 Views)
Right-Click on the "Format into String" vi and select "Edit Format
String"

it was too easy - right ?

/Per-Eric

Ed Dickens wrote:
>
> Thanks Martin, that did the trick, I figured it was simple.
>
> One other quick question to see if I understand the format string.
>
> It looks like this one breaks down as follows.
>
> 0 = left fill with 0
> 6 = bit count for the string, including the decimal
> 3 = number of decimal places
> f = ???
>
> I've looked through all my documentation and cannot find a description
> of how the format strings or codes work. do you know where I can find
> this info?
>
> > The correct format string is %06.3f
> >
> > Martin
> >
> > --
> > Martin Henz Systemtechnik
> > Dipl. Ing. (FH) Martin Henz
> > Rochenweg 1
> > 7
0378 Stuttgart
> > Tel. ++49-711-5302605
> > Fax ++49-711-5058649
> > http://www.mhst.de
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
0 Kudos
Message 4 of 7
(4,589 Views)
"Ed Dickens" schrieb im Newsbeitrag news:8v3u4v$uk0$1@nnrp1.deja.com...
> Thanks Martin, that did the trick, I figured it was simple.
>
> One other quick question to see if I understand the format string.
>
> It looks like this one breaks down as follows.
>
> 0 = left fill with 0
> 6 = bit count for the string, including the decimal
> 3 = number of decimal places
correct

> f = ???
f means "to floating-point number with fractional format"

>
> I've looked through all my documentation and cannot find a description
> of how the format strings or codes work. do you know where I can find
> this info?
Right click on the Format Into String function and select Edit Format String. In
this case a dialog box opens where you can
build the format string.

The difficult way is to find the format specifiers table in the labview
online documentation ...it seems that NI wants to hide this information 😆
The format specifiers are similar to those used in the printf function
of a C compiler. Search in the help index for "formatting: specifiers in strings"
or "formatting strings".

Martin

>
>
> > The correct format string is %06.3f
> >
> > Martin
> >
> > --
> > Martin Henz Systemtechnik
> > Dipl. Ing. (FH) Martin Henz
> > Rochenweg 1
> > 70378 Stuttgart
> > Tel. ++49-711-5302605
> > Fax ++49-711-5058649
> > http://www.mhst.de
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
0 Kudos
Message 5 of 7
(4,589 Views)
Ed,

you doing well, just use format string of < %06.3f >it will works for all
positive values up to
99.999999.. for negative values change 6 by 7.

Ilan



"Ed Dickens" wrote in message
news:8v3nan$ohr$1@nnrp1.deja.com...
> I'm new to Labview so this might be a simple one.
>
> I'm trying to control a power supply on a com port. The problem I'm
> having is when trying to set the voltage and current. The power supply
> needs the string in the format of xx.xxx, it must have all 5 digits or
> it will not recognize it as a valid command.
>
> Here's the process I'm using.
>
> First I read a control for the voltage setting from the front panel,
> then use the "Format Value" function with a format string of %.3 to
> convert the value to a string with 3 decima
l places. This works fine for
> any value over 10, but any lower value doesn't have the tens digit and
> only outputs x.xxx. I need to get a leading 0 on anything under 10.
>
> I've actually figured out a way to it by counting the output string
> length and using an "Append true/false String", but this ends up messing
> up the values over 10.
>
> Is there another format string syntax that will force 2 places before
> the decimal?
>
> Thanks
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
0 Kudos
Message 6 of 7
(4,589 Views)
[posted and mailed]

eodickens@excite.com (Ed Dickens) wrote in <8v3nan$ohr$1@nnrp1.deja.com>:

>I'm new to Labview so this might be a simple one.
>
>I'm trying to control a power supply on a com port. The problem I'm
>having is when trying to set the voltage and current. The power supply
>needs the string in the format of xx.xxx, it must have all 5 digits or
>it will not recognize it as a valid command.
>
>Here's the process I'm using.
>
>First I read a control for the voltage setting from the front panel,
>then use the "Format Value" function with a format string of %.3 to
>convert the value to a string with 3 decimal places. This works fine for
>any value over 10, but any lower value doesn't have the tens digit and
>only outputs x.xxx. I need to get a leading 0 on anythi
ng under 10.
>
>I've actually figured out a way to it by counting the output string
>length and using an "Append true/false String", but this ends up messing
>up the values over 10.
>
>Is there another format string syntax that will force 2 places before
>the decimal?

This has benn answered by others, but did you know you can double click on
the "Format Into String" and "Scan From String" icons. This will bring up a
dialog box that will allow you to slect zero leading, number of dp's, etc

Alex.

--

Alexander C. Le Dain, PhD
ICON Technologies Pty Ltd
http://www.icon-tech.com.au

******************************************************************
* The LabVIEW FAQ http://www.icon-tech.com.au/thelabviewfaq.html *
******************************************************************
0 Kudos
Message 7 of 7
(4,589 Views)