LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

format into SI string (always kHz)

Solved!
Go to solution

Hello,

 

I'm reading DBL sample rate values from different RF bands and using the value to create a file header in order to store complex 32IQ binary data to file. I'm using the format into string function to do this but I always want the sample rate to be represented in kHz and I haven't thought of a way to force this to always be the case. I'm using a format string of %.3p which for sample rates such as 13125 and 400000 it returns 13.125k and 400.000k respectively and that is what I want. However, one of my bands is 3750000 Hz and the format into string returns 3.750M. I would like it to return 3750.000k instead. Anyone have any ideas on how I could accomplish this?

 

Thank you,

 

Tim



Tim Sileo
RF Applications Engineer
National Instruments



You don’t stop running because you get old. You get old because you stop running. -Jack Kirk, From "Born to Run" by Christopher McDougall.
0 Kudos
Message 1 of 7
(3,173 Views)

Tim,

 

Since the 3.750M is the correct format for the value and what you want is valid but not standard, you will need to do your own formatting.

 

You need to test the string coming from the format function. If it contains "M" then multiply by 1000 and append "k".

 

Lynn

0 Kudos
Message 2 of 7
(3,154 Views)
Solution
Accepted by topic author TimS.

If you divide the dbl value by 1000 and then apply the format into string with the %.3f specifier you will have the kHz value.

 

Ben

Message 3 of 7
(3,154 Views)

I would guss that the internal code that shows the SI units is using the 'multiples of three' flag to determine the magnitude. If you use the advanced properties to select between engineering and SI units, the 'multiples of three' box is disabled when you select SI. 

 

I experimented with various display formats, but could not get the combination you indicated.

 

I believe the SI standard reccommends that prefixes for which the exponent is divisible by three are used.( http://en.wikipedia.org/wiki/SI_prefix#List_of_SI_prefixes )

 

LabVIEW is displaying the number to the SI standard. Your desired display type is not standard SI units (although it may be common and practical in your environment/industry).


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

0 Kudos
Message 4 of 7
(3,137 Views)

Just as Ben said was the way I decided to implement it.

 

My numeric data inputs are always in Hz. So, I just always divide the DBL values by 1000 before inputting them into the "format into string" function and changed the format string to output %.3f. This way, the output was in kHz just without the letter suffix. I just append "k" myself afterwards. Thanks Ben.

 

I was trying to condense the multiple steps all into the "format into string" function but it wouldn't work for all my sample rate values.

 

-Tim



Tim Sileo
RF Applications Engineer
National Instruments



You don’t stop running because you get old. You get old because you stop running. -Jack Kirk, From "Born to Run" by Christopher McDougall.
0 Kudos
Message 5 of 7
(3,101 Views)

There's no need to 'add the "k" afterwards' if you use "%.3fk" as the format specifier in your format to string.

 

Rod.

 

Message 6 of 7
(3,087 Views)

Good point. I forgot that I could add non-conversion related text into the format string. Helps clean up the diagram a little bit too.


Thanks,


Tim



Tim Sileo
RF Applications Engineer
National Instruments



You don’t stop running because you get old. You get old because you stop running. -Jack Kirk, From "Born to Run" by Christopher McDougall.
0 Kudos
Message 7 of 7
(3,083 Views)